0
我正在通過gmap3 plugin谷歌地圖。在這裏我已經從谷歌地圖代碼中獲得longitude value and latitude value
。現在我想要這個值的地址,如country name state name and city name etc
。那麼如何從longitude and latitude
值中獲得這些值。我的代碼看起來像這樣谷歌地圖得到經度和緯度值的總地址
jQuery(document).ready(function() {
jQuery('#map').blur(function() {
//console.log('hello');
var the_address = jQuery(this).val();
var geocoder = new google.maps.Geocoder();
var latLng = geocoder.geocode({
address: the_address
}, function(results, status) {
/// IF WE HAVE A RESULT
if(status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
jQuery('#latitude').val(lat);
jQuery('#longitude').val(lng);
jQuery(gMap).gmap3({
get: {
name: 'marker',
all: true,
callback: function(objs) {
jQuery.each(objs, function(i, obj) {
obj.setMap(null);
})
}
},
map: {
options: {
zoom: 10,
center: new google.maps.LatLng(lat, lng)
}
},
marker: {
values: [{ latLng:[lat, lng] }],
//jQuery(console.log(values));
options: {
draggable: true,
icon: new google.maps.MarkerImage(
"http://gmap3.net/skin/gmap/magicshow.png",
new google.maps.Size(32, 37, "px", "px")
),
},
events: {
mouseup: function(marker, event, context) {
//// GETS MARKER LATITUDE AND LONGITUDE
var thePos = marker.getPosition();
var theLat = thePos.jb;
var theLng = thePos.kb;
jQuery('#latitude').val(theLat);
jQuery('#longitude').val(theLng);
},
dragend: function(marker, event, context) {
jQuery(this).gmap3({
getaddress:{
latLng:marker.getPosition(),
callback:function(results){
var map = $(this).gmap3("get"),
infowindow = $(this).gmap3({get:"infowindow"}),
content = results && results[1] ? results && results[1].formatted_address : "no address";
if (infowindow){
infowindow.open(map, marker);
infowindow.setContent(content);
} else {
jQuery(this).gmap3({
infowindow:{
anchor:marker,
options:{content: content}
}
});
}
}
}
});
},
}
}
});
} else {
alert('Could not find the latitude and longitude for the address '+the_address);
}
});
});
});
任何幫助和建議都將非常可觀。謝謝
你想去哪裏得到的?您只需使用Lat和Lng反轉地理代碼即可獲取完整地址。 – putvande