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

问题描述

|| 这是我的v2代码有效(标记未显示)
<body onload=\"load()\"> 

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

<script type=\"text/javascript\"> 

var userLocation = \'<?php echo $address; ?>\';
如果(GBrowserIsCompatible()){    var geocoder = new GClientGeocoder();    geocoder.getLocations(userLocation,函数(位置){       如果(locations.Placemark)       {          var north = location.Placemark [0] .ExtendedData.LatLonBox.north;          var south = location.Placemark [0] .ExtendedData.LatLonBox.south;          var east = location.Placemark [0] .ExtendedData.LatLonBox.east;          var west = location.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),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中有效)获取的中心定位在我们的坐标上 任何帮助表示赞赏。     

解决方法

您只需要将自定义图片的网址传递给Marker初始化中的图标键
var marker = new google.maps.Marker({
  map: map,position: results[0].geometry.location,title: \'userLocation\',icon: \'images/422marker.png\'
});
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...