2012-03-19 34 views
0

我想使用GoogleMaps API v3。 之前,我使用的是版本2,我只是把地址和地图显示出来。 版本n°3总是可以的吗? 如果是,如何? 我总是找到有纬度,经度的脚本......但没有地址的脚本。 非常感谢,并为我可怜的英语感到抱歉。是否可以只显示地图的地图?

+0

你的英语非常好。 – defau1t 2012-03-19 20:00:56

回答

0

我想你混合了Maps-Javascript-API和Static-Maps-API(当前版本是V2)。

在static-maps-API中,您可以使用地址作为中心参数。

在JavaScript-API中,您需要一个LatLng(无论是V2还是V3)。如果您只有地址,则必须使用地理编码请求来请求LatLng。

+0

要请求LatLng,脚本是否存在? 我不想让它在网站上,但我希望LatLng提供地址,这有可能吗?如果是,在哪里? 再次感谢。 – user1278739 2012-03-19 15:46:12

+1

是的:文档中有一个例子。 https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple – 2012-03-19 15:59:10

+0

非常感谢您;) – user1278739 2012-03-19 16:04:43

0

基本上你需要寻找一种叫geocode的东西。它是API文档的一部分。像下面将帮助:

var geocoder; 
    var map; 
    function initialize() { 
    geocoder = new google.maps.Geocoder(); 
    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); 
    } 

    function codeAddress() { 
    var address = document.getElementById("address").value; 
    geocoder.geocode({ 'address': address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
     map.setCenter(results[0].geometry.location); 
     var marker = new google.maps.Marker({ 
      map: map, 
      position: results[0].geometry.location 
     }); 
     } else { 
     alert("Geocode was not successful for the following reason: " + status); 
     } 
    }); 
    } 

Helpful Link

相关问题