通过传递地名以编程方式在 google 地图 API 中搜索地点
programatically search a place in google map API by passing place name
我想在 google 地图 api 中传递一个地名并使用它我需要提取我在 gogle map.This 左侧的那个地方的描述应该完成以编程方式,即我在数据库中有一个位置列表,我会将这些数据传递给 API 并需要获取 type.If 我通过肯德基然后我需要从其输出中提取 "Chicken Restaurant" 关键字,我不确定是否可能!如果可能,那么输出将采用哪种格式,XML 或其他格式??
使用JSON
<?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");
?>
使用XML
<?php
function place_ID($location)
{
$locationclean = str_replace (" ", "+", $location);
$data = "https://maps.googleapis.com/maps/api/place/textsearch/xml?query=" . $locationclean . "&key=YOUR_KEY";
$xml = file_get_contents($data);
$xml = simplexml_load_string($xml);
foreach($xml->result->type as $key => $value){
$location_id = $value;
echo $location_id;
echo "<br>";
}
}
place_ID("kfc");
?>
我想在 google 地图 api 中传递一个地名并使用它我需要提取我在 gogle map.This 左侧的那个地方的描述应该完成以编程方式,即我在数据库中有一个位置列表,我会将这些数据传递给 API 并需要获取 type.If 我通过肯德基然后我需要从其输出中提取 "Chicken Restaurant" 关键字,我不确定是否可能!如果可能,那么输出将采用哪种格式,XML 或其他格式??
使用JSON
<?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");
?>
使用XML
<?php
function place_ID($location)
{
$locationclean = str_replace (" ", "+", $location);
$data = "https://maps.googleapis.com/maps/api/place/textsearch/xml?query=" . $locationclean . "&key=YOUR_KEY";
$xml = file_get_contents($data);
$xml = simplexml_load_string($xml);
foreach($xml->result->type as $key => $value){
$location_id = $value;
echo $location_id;
echo "<br>";
}
}
place_ID("kfc");
?>