开发者

Google Maps API JS: Show map of a certain town

Isn't it any longer possible in Google Maps API V3 (JavaScript) to display a marker at a setted/given town name? This is my code:

google.maps.event.addDomListener(window, 'load', function() {
var myOptions = {
  zoom: 8,
  center: new google.maps.LatLng(-34.397, 150.6开发者_运维问答44),
  mapTypeId: google.maps.MapTypeId.ROADMAP
};
new google.maps.Map(document.getElementById('locate'), myOptions);

There is the line center: new google.maps.LatLng(-34.397, 150.644) but I haven't the LatLng-Coordinates; just the town name. How could I display now the marker based on the name?


Two options... First, you can use the Google Geocoding API, which allows you to find the Lat/Lng of a site on the fly. Second, you can use this method, which requires a database.


If you're working with a limited set of towns, I'd suggest you create your own DB or hashmap of town names to latlng coordinates. Otherwise use either of Chris's suggestions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜