cdub
cdub

Reputation: 25701

URL and Geolocation of addresses

Is there any function to turn this:

1600 Amphitheatre Parkway, Mountain View, CA":

into this:

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

Building a google map using their geolocation.

Upvotes: 0

Views: 357

Answers (1)

Rupesh Patel
Rupesh Patel

Reputation: 3065

You can directly pass '1600 Amphitheatre Parkway, Mountain View, CA' Use Following function

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

It will return geoLocation of the address in array

Upvotes: 1

Related Questions