Php 地址的URL和地理位置

Php 地址的URL和地理位置,php,encoding,google-maps-api-3,geolocation,Php,Encoding,Google Maps Api 3,Geolocation,是否有任何功能可以打开此功能: 1600 Amphitheatre Parkway, Mountain View, CA": 为此: 1600+Amphitheatre+Parkway,+Mountain+View,+CA 使用他们的地理位置构建谷歌地图。你可以直接通过加州山景城1600圆形剧场公园路 使用以下函数 public function GetGeoLocation($address) { // fetching lat&lng f

是否有任何功能可以打开此功能:

1600 Amphitheatre Parkway, Mountain View, CA":
为此:

1600+Amphitheatre+Parkway,+Mountain+View,+CA

使用他们的地理位置构建谷歌地图。

你可以直接通过加州山景城1600圆形剧场公园路 使用以下函数

 public function GetGeoLocation($address)
        {
        // fetching lat&lng from Google Maps
        $request_uri = 'http://maps.googleapis.com/maps/api/geocode/xml?address='.urlencode($address).'&sensor=true';
        $google_xml = simplexml_load_file($request_uri);
        $lat = (string)$google_xml->result->geometry->location->lat;
        // fetching time from earth tools
        $lng = (string)$google_xml->result->geometry->location->lng;
        return array('lat' => $lat,'lng' => $lng)
        }

它将返回数组中地址的地理位置

我还假设它不仅可以将空格转换为加号,还可以将其他字符转换为其他字符。您可能在谈论或。str_replace(“,“+”,$address)urlencode将起作用,但仍然可以将逗号转换为编码字符