Home > php教程 > php手册 > 通过php获取google map的坐标地址

通过php获取google map的坐标地址

WBOY
Release: 2016-06-13 09:40:06
Original
1743 people have browsed it

 第一步,获取坐标

<?php $address = !empty($_POST['address'])?$_POST['address']:"<?=$navinfor[字段名称]?>";// Google HQ
$prepAddr = str_replace(' ','+',$address);
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$lng = $output->results[0]->geometry->location->lng;
?>
第二步,将获取到的坐标嵌入到地图即可
<img  src="http://maps.google.com/maps/api/staticmap?center=<?php%20echo%20%24lat;?>,%0A<?php%20echo%20%24lng;?>&%0Azoom=16&%0Asize=520x340&%0Amaptype=roadmap&%0Amarkers=<?php%20echo%20%24lat;?>,<?php%20echo%20%24lng;?>&%0Asensor=false"    style="max-width:90%"  style="max-width:90%" alt="通过php获取google map的坐标地址" >

代码就两段,很简单。
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template