2015-12-27 73 views
-1

夥計!谷歌地圖 - 通過街道地址給出座標

我現在工作的權利在我的項目之一,並不能找到這樣的方式添加標記的方式:我有一個數組

,其中有座標和對一些其他信息這些標記。

lat = 0; lng = 0; 

但我感興趣的是給予座標的Google.Map,像這樣的另一種方式:

Augsburger Straße, Augsburg, Deutschland

,這是非常有趣的,如果有什麼辦法可以在此添加標記辦法?

回答

0

是的,看到https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingRequests

例如

function initMap() { 
    var map = new google.maps.Map(document.getElementById('map'), { 
    zoom: 8, 
    center: {lat: -34.397, lng: 150.644} 
    }); 
    var geocoder = new google.maps.Geocoder(); 

    geocoder.geocode({'address': 'Augsburger Straße, Augsburg, Deutschland'}, 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); 
    } 
    }); 
} 
+0

非常感謝,真的幫助我:) –