Created
July 5, 2012 13:39
-
-
Save ekka21/3053707 to your computer and use it in GitHub Desktop.
Get lat and lng from google map api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getLatandLong($addr,$city,$state) | |
{ | |
global $lat; | |
global $lng; | |
$doc = new DOMDocument(); | |
$doc->load("http://maps.google.com/maps/api/geocode/xml?address=".$addr.",+".$city.",+".$state."&sensor=false"); //input address | |
//traverse the nodes to get to latitude and longitude | |
$results = $doc->getElementsByTagName("result"); | |
$results = $results->item(0); | |
$results = $results->getElementsByTagName("geometry"); | |
$results = $results->item(0); | |
$results = $results->getElementsByTagName("location"); | |
foreach($results as $result) | |
{ | |
$lats = $result->getElementsByTagName("lat"); | |
$lat = $lats->item(0)->nodeValue; | |
$lngs = $result->getElementsByTagName("lng"); | |
$lng = $lngs->item(0)->nodeValue; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment