Skip to content

Instantly share code, notes, and snippets.

@sh1mmer
Created July 10, 2009 22:04
Show Gist options
  • Save sh1mmer/144854 to your computer and use it in GitHub Desktop.
Save sh1mmer/144854 to your computer and use it in GitHub Desktop.
$input = "some text";
$query = "select centroid.latitude, centroid.longitude from geo.places where text='$input'";
$url = "http://query.yahooapis.com/v1/public/yql?q=" . urlencode($query) . "&format=json&callback=";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$results = json_decode($response, true);
$results = $results["query"]["results"];
if (count($results["place"]) == 1) {
$lat = $results["place"]["centroid"]["latitude"];
$long = $results["place"]["centroid"]["longitude"];
} else {
$lat = $results["place"][0]["centroid"]["latitude"];
$long = $results["place"][0]["centroid"]["longitude"];
}
if (!(lat & long)) {
//put code in here for when there isn't a match.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment