2011-05-23 122 views
0

这是我v2的代码工作(标记没有显示)GMAP V2 - > V3(自定义标记没有显示+如何添加php的地址)

<body onload="load()"> 

<div id="map_canvas" style="width: 520px; height: 370px"></div> 

<script type="text/javascript"> 

var userLocation = '<?php echo $address; ?>'; 

如果(GBrowserIsCompatible()){ VAR地理编码器= new GClientGeocoder(); geocoder.getLocations(用户位置,功能(位置){
如果(locations.Placemark) { 变种北= locations.Placemark [0] .ExtendedData.LatLonBox.north; 变种南= locations.Placemark [0]。 ExtendedData.LatLonBox.south; 变种东= locations.Placemark [0] .ExtendedData.LatLonBox.east; 变种西= locations.Placemark [0] .ExtendedData.LatLonBox.west;

 var bounds = new GLatLngBounds(new GLatLng(south, west), 
            new GLatLng(north, east)); 

    var map = new GMap2(document.getElementById("map_canvas")); 

     var Icon = new GIcon(); 
     Icon.image = "images/422marker.png"; 
     Icon.iconSize = new GSize(33, 50); 

    map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)); 
    map.addOverlay(new GMarker(bounds.getCenter()), Icon); 
    } 

}); }

这里是我的V3代码(标记不显示的问题不知道如何利用我们的PHP用户位置的地址脚本)

<body onload="load()"> 

<div id="map_canvas" style="width: 520px; height: 370px"></div> 

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 


<script type="text/javascript"> 
var userLocation = '5th Avenue, New York'; 

var latlng = new google.maps.LatLng(-34.397, 150.644); 
var myOptions = { 
    zoom: 8, 
    center: latlng, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
}; 
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

var geocoder = new google.maps.Geocoder(); 

geocoder.geocode({ 'address': userLocation}, function(results, status) { 

    if (status == google.maps.GeocoderStatus.OK) { 
    // Geolocation was sucessfull 

    // Set Marker Icon 
    var icon = new google.maps.MarkerImage('images/422marker.png', 
     new google.maps.Size(33,50), 
     new google.maps.Point(0,0), 
     new google.maps.Point(0,32)); 


    // Move map to position and set zoom 
    map.setCenter(results[0].geometry.location); 
    map.setZoom(11); 

    var marker = new google.maps.Marker({ 
     map: map, 
     position: results[0].geometry.location, 
     title: userLocation 
     //icon: icon 
     }); 
    } else { 
    alert("Geocode was not successful for the following reason: " + status); 
    } 

}); 

所以我有这个问题是folows:

V2:

自定义标记没有显示,所以更新的地图,以V3

V3:

自定义标记不显示+不知道如何使用我们的PHP代码中心从另一个脚本在我们的坐标中的地图,获取的(在V2的工作)

任何帮助表示赞赏。

回答

0

你只需要通过网址为您的自定义图像图标键的标记初始化

var marker = new google.maps.Marker({ 
    map: map, 
    position: results[0].geometry.location, 
    title: 'userLocation', 
    icon: 'images/422marker.png' 
}); 
相关问题