Recently, I am working on an application where I have to convert addresses to their corresponding Lat and Lon. So, I decided to write on how to get Latitude and Longitude in Google Maps using only PHP. To use the technique explained below, you need to have a Google Maps Key . The idea is simple. Make a request to Google Maps server, and it will return an XML (or JSON). Then, parse the XML to get the Lat and Lon. I use DomDocument and DomXPath for processing it. Below I have used the address: 100 City Centre Dr., Mississauga, Ontario . 1. $key = "....." ; // your Google Maps key 2. 3. $address = urlencode( '100 City Centre Dr., Mississauga, ON' ); 4. 5. $url = ' http://maps.google.com/maps/geo?q= ' . $address . '&output=xml&oe=utf8&key=' . $key ; 6. $dom = new DomDocument(); 7. $dom ->load( $url ); At this point, the XML is loaded into the $dom. Now, it...
Comments
Post a Comment