[英]How will we convert latitude and longitude to the address in web site?
我有一個提供緯度和經度的API,我想要基於值的地點(城市,區域等)的地址。
假設如果我們提供位置ip,則類似http://ip-api.com/php/2.50.153.139的網站,它將給出我們所居住位置的名稱。 json輸出將類似於:
a:14:{s:5:"query";s:12:"2.50.153.139";s:10:"regionName";s:9:"Abu Dhabi";s:3:"lat";d:24.466699600219727;s:3:"org";s:39:"Emirates Telecommunications Corporation";s:3:"zip";s:0:"";s:2:"as";s:24:"AS5384 Emirates Internet";s:6:"status";s:7:"success";s:7:"country";s:20:"United Arab Emirates";s:4:"city";s:9:"Abu Dhabi";s:3:"lon";d:54.36669921875;s:8:"timezone";s:10:"Asia/Dubai";s:3:"isp";s:39:"Emirates Telecommunications Corporation";s:11:"countryCode";s:2:"AE";s:6:"region";s:2:"AZ";}
但是在畝的情況下,我有緯度,經度,我想要地區名稱。
我需要使用php或js,該怎么辦?
包含此腳本- <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
然后 : -
<script type="text/javascript">
function GetAddress() {
var lat = parseFloat(document.getElementById("#yourinputlat").value);
var lng = parseFloat(document.getElementById("#yourinputlon").value);
var latlng = new google.maps.LatLng(lat, lng);
var geocoder = geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
alert("Location: " + results[1].formatted_address);
}
}
});
}
</script>
用下面的URL和數據制作Ajax-> lat和long
http://maps.googleapis.com/maps/api/geocode/json?latlng=44.4647452,7.3553838&sensor=true
您應該嘗試這一方法,並且正在尋找Google(或其他任何人)的反向地理編碼服務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.