本文介绍了街道名称的地理坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法(使用 rest API 会很棒)来获取与地理坐标相对应的街道名称?我想名字是地理编码,谷歌有这个API吗?我是 PHP 开发人员.
is any way (with a rest API will be awesome) to get the Street name corresponding to a Geographical coordinate? I think the name is geocoding, do google have this API? Im PHP developer.
例如.
<?php
cor="38.115583,13.37579";
echo(geoname(cor)); // this prints: Foro Umberto I - 90133 Palermo
?>
所以函数的输出是街道名称、邮政编码和城市.感谢您提供任何帮助和脚本示例!
So the output of the function is the street name, the postal code and the city. Thanks for any help and scripts examples!
推荐答案
是的,只需使用 Google Maps API 中的反向地理编码"功能:http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding
Yes, just use the "Reverse Geocoding" function in the Google Maps API: http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding
这是一些示例代码:
$lat="38.115583";
$long = "13.37579";
$url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$long&sensor=false";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_ENCODING, "");
$curlData = curl_exec($curl);
curl_close($curl);
$address = json_decode($curlData);
print_r($address);
这篇关于街道名称的地理坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!