[英]How will we convert latitude and longitude to the address in web site?
I have an API which gives latitude and longitude and i want the address of the place(city,area etc) based on the values. 我有一个提供纬度和经度的API,我想要基于值的地点(城市,区域等)的地址。
Suppose the website like http://ip-api.com/php/2.50.153.139 if we give the ip of the location ,it will give the name of the location that we residing. 假设如果我们提供位置ip,则类似http://ip-api.com/php/2.50.153.139的网站,它将给出我们所居住位置的名称。 The json output will be like:
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";}
But in mu case i have latitude ,longitude and i want the area name. 但是在亩的情况下,我有纬度,经度,我想要地区名称。
I need it either by using php or by js .How can i do it? 我需要使用php或js,该怎么办?
include this script - <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
包含此脚本-
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
Then : - 然后 : -
<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>
Make ajax with below url and data -> lat and long 用下面的URL和数据制作Ajax-> lat和long
http://maps.googleapis.com/maps/api/geocode/json?latlng=44.4647452,7.3553838&sensor=true http://maps.googleapis.com/maps/api/geocode/json?latlng=44.4647452,7.3553838&sensor=true
您应该尝试这一方法,并且正在寻找Google(或其他任何人)的反向地理编码服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.