Heim  >  Artikel  >  Backend-Entwicklung  >  通过php获取google map的坐标地址_PHP教程

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

WBOY
WBOYOriginal
2016-07-13 10:35:071579Durchsuche

 第一步,获取坐标

<?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的坐标地址_PHP教程" >

代码就两段,很简单。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/746588.htmlTechArticle第一步,获取坐标 ?php$address = !empty($_POST['address'])?$_POST['address']:?=$navinfor[字段名称]?;// Google HQ$prepAddr = str_replace(' ','+',$address);$geocode=file_g...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn