php 获取Google地图的纬度和经度

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 获取Google地图的纬度和经度相关的知识,希望对你有一定的参考价值。

<?php

$address = 'Visalia, CA, USA'; // any address you want latitude and longitude of

$address_encoded = urlencode($address);
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=". $address_encoded ."&key=YOUR_API_KEY";
$result = file_get_contents($url);
$geocode = json_decode($result, true); // returing json of all information about given address
$location = $geocode['results'][0]['geometry']['location'];

$location_lat = $location['lat'];
$location_lng = $location['lng'];

// google maps documentaiotn referrence https://developers.google.com/maps/documentation/geocoding/start

以上是关于php 获取Google地图的纬度和经度的主要内容,如果未能解决你的问题,请参考以下文章