Google Maps API JS:显示某个城镇的地图

时间:2011-09-23 21:20:13

标签: google-maps google-maps-api-3 google-api

在Google Maps API V3(JavaScript)中,在设定/给定的城镇名称上显示标记是不是更久了?这是我的代码:

google.maps.event.addDomListener(window, 'load', function() {
var myOptions = {
  zoom: 8,
  center: new google.maps.LatLng(-34.397, 150.644),
  mapTypeId: google.maps.MapTypeId.ROADMAP
};
new google.maps.Map(document.getElementById('locate'), myOptions);

center: new google.maps.LatLng(-34.397, 150.644)行,但我没有LatLng坐标;只是镇名。我怎样才能根据名称显示标记?

2 个答案:

答案 0 :(得分:2)

两个选项......首先,您可以使用Google Geocoding API,这样您就可以动态查找网站的Lat / Lng。其次,您可以use this method,这需要一个数据库。

答案 1 :(得分:1)

如果您正在使用一组有限的城镇,我建议您创建自己的城镇名称数据库或哈希映射到latlng坐标。否则请使用Chris的建议。