通过传递地名,以编程方式在Google地图API中搜索某个地点

时间:2016-05-11 09:20:00

标签: google-maps search google-maps-api-3 google-maps-api-2

我想在谷歌地图api中传递一个地名并使用我需要提取我在gogle地图中左侧的那个地方的描述。这应该以编程方式完成,即我在数据库中有一个地方列表,我和#39;将这些数据传递给API并需要获取类型。如果我通过肯德基,那么我需要提取"鸡肉餐厅"输出中的关键字,我不确定是否可能!如果可能,则输出将采用哪种格式,XML或其他?

1 个答案:

答案 0 :(得分:0)

使用JSON

<ul class="iconhaken">
	<li>Jede Uni hat Seelsorge-Stellen. Erkundige dich dort mal. Alternativ kannst du über folgende Website per Mail oder per Chat eine kostenlose Beratung erhalten.</li>
	<li>Jetzt bist du optimal auf deine Prüfungen vorbereitet. Also Ruhe bewahren und viel Erfolg!</li>
</ul>

使用XML

<?php
function geoPlaceID($location)
{
   $locationclean = str_replace (" ", "+", $location);
   $details_url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=" . $locationclean . "&key=YOUR_KEY";
   $du = file_get_contents($details_url);

   $getDetails = json_decode(utf8_encode($du),true);
   if ($getDetails['status']=="OK")
   {
       $a=$getDetails['results'][1]['types'];
       print_r($a);
      // echo implode(" ",$a)."<br>";
   }
   else
   {
       echo "Place ID not found";
   }
}
geoPlaceID("kfc");
 ?>
相关问题