如何使用google Api查找经度和纬度?
答
我想你在找Google Goocles Api。
你发送一个请求像这样的东西: https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY
再大的JSON对象回来,在那里你可以得到lat和长
“的结果 - 几何 - 位置 - 纬度/经度”
{
"results" : [
{
"geometry" : {
"location" : {
"lat" : 37.4224764,
"lng" : -122.0842499
},
...
...
看看这里获取更多一些信息https://developers.google.com/maps/documentation/geocoding/intro
答
第一次加载库:
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?
key=YOUR_API_KEY&libraries=places">
</script>
然后找到具体位置的细节:
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -33.866, lng: 151.196},
zoom: 15
});
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4'
}, function(place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' +
'Place ID: ' + place.place_id + '<br>' +
place.formatted_address + '</div>');
infowindow.open(map, this);
});
}
});
}
更换纬度和所需位置的经度。
更多细节请参考:
https://developers.google.com/maps/documentation/javascript/places#place_details
并且例如:
https://developers.google.com/maps/documentation/javascript/examples/place-details