gmap v2 - > v3(自定义标记未显示+如何添加php地址)

时间:2011-05-23 21:58:45

标签: php google-maps

这是我的v2代码(标记没有显示)

<body onload="load()"> 

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

<script type="text/javascript"> 

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

if(GBrowserIsCompatible()){    var geocoder = new GClientGeocoder();    geocoder.getLocations(userLocation,function(locations){
      if(locations.Placemark)       {          var north = locations.Placemark [0] .ExtendedData.LatLonBox.north;          var south = locations.Placemark [0] .ExtendedData.LatLonBox.south;          var east = locations.Placemark [0] .ExtendedData.LatLonBox.east;          var west = 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 userLocation地址脚本)

<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);
  }

});

所以我遇到的问题如下:

v2:

自定义标记未显示,因此更新后的地图为v3

v3:

自定义标记没有显示+不确定如何使用我们的PHP代码将地图置于我们的坐标中心,从另一个脚本(在v2中工作)获取

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:0)

您只需将自定义图片的网址传递给标记初始化

中的图标键即可
var marker = new google.maps.Marker({
  map: map,
  position: results[0].geometry.location,
  title: 'userLocation',
  icon: 'images/422marker.png'
});