本文介紹了谷歌地圖 - 當前位置的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想獲取當前用戶位置的地址字符串.這可能嗎?
I would like to get the address string of the current user location. Is that possible?
非常感謝.問候
推薦答案
如果你想獲取街道地址!
包括 JS 和 MAP Api Key,從向導中保持在一起
include both JS and MAP Api Key, keep all together from the wizard
我的代碼如下所示:(也使用了一點 jQuery)
my code look like this: (use also a bit of jQuery)
var geocoder = null;
var lat = null;
var lng = null;
$(function() {
if (GBrowserIsCompatible()) {
if (google.loader.ClientLocation &&
// i used this here cause not always
//this retrieve the correct LAT & LON
// so set it manually
google.loader.ClientLocation.address.country_code == "IT" ) {
lat = google.loader.ClientLocation.latitude;
lng = google.loader.ClientLocation.longitude;
} else {
//alert( 'Insert Your Latitude & longitude manually!' );
lat = '42.464826';
lng = '14.214095';
}
//creat the full LAT + LON
points = new GLatLng( lat , lng );
//get the Street Address
get_address(points);
}
});
function get_address(latlng) {
if (latlng) {
geocoder = new GClientGeocoder();
geocoder.getLocations(latlng, function(addresses) {
if(addresses.Status.code != 200) {
alert("reverse geocoder failed to find an address for " + latlng.toUrlValue());
}
else {
address = addresses.Placemark[0];
var myHtml = address.address;
$('#address').text(myHtml);
}
});
}
};
peraphs 閱讀此鏈接也可能有所幫助:
peraphs read this link may help too:
獲取經緯度對的街道地址
這篇關于谷歌地圖 - 當前位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!