将位置标记放在地图中?

时间:2011-03-18 07:04:05

标签: google-maps-api-2

这里我要显示此latlng的引脚(标记)点位置地址?在这里我发送一个中心,我也必须向API发送两个或更多中心(latlng)并获得更多的标记位置。

jQuery的:

var map;
var geocoder;
var address;

function initialize() {
  map = new GMap2(document.getElementById("map_canvas"));
  map.setCenter(new GLatLng(13.0423734,80.2727993), 10);
  map.setUIToDefault();
  geocoder = new GClientGeocoder();
}

HTML:

<body onload="initialize()">
  <div id="map_canvas" style="height:550px; width:950px">
  </div>
  </body>

我包含此代码:

    map.setCenter(point, 13);
    var marker = new GMarker(point);
    map.addOverlay(marker);

1 个答案:

答案 0 :(得分:1)

var map;
var geocoder;
var address;

function initialize() {
  map = new GMap2(document.getElementById("map_canvas"));
  map.setCenter(new GLatLng(13.0423734,80.2727993), 10);
  map.setUIToDefault();
  geocoder = new GClientGeocoder();
}


function showAddress(address) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 13);
        var marker = new GMarker(point);
        map.addOverlay(marker);
      }
    }
  );
}

资源: http://code.google.com/apis/maps/documentation/javascript/v2/services.html#Geocoding