【问题标题】:URL and Geolocation of addresses地址的 URL 和地理位置
【发布时间】:2012-07-23 13:34:15
【问题描述】:

有什么功能可以转这个:

1600 Amphitheatre Parkway, Mountain View, CA":

进入这个:

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

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

【问题讨论】:

  • 我还假设它不仅可以将空格变为加号,还可以将其他字符变为其他字符。
  • 您可能在谈论urlencoderawurlencode
  • str_replace(" ", "+", $address)
  • urlencode 可以工作,但仍将逗号转换为编码字符

标签: php encoding google-maps-api-3 geolocation


【解决方案1】:

您可以直接通过“1600 Amphitheatre Parkway, Mountain View, CA” 使用跟随功能

 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)
        }

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多