在`search.php`文件中,我们可以使用地理编码服务将关键字转换为经纬度,然后使用地理搜索服务查找附近的相关地点。以下是一个示例代码:
php
results[0]->geometry->location->lat;
$lng = $data->results[0]->geometry->location->lng;// 地理搜索
$url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=' . $lat. ',' . $lng . '&radius=500&type=car_repair&key=YOUR_API_KEY';
$json = file_get_contents($url);
$data = json_decode($json);// 输出结果
echo '
';
foreach ($data->results as $result) {echo '
-
' . $result->name . ' (' . $result->vicinity . ')
';
}
echo '
';