Created
July 18, 2012 22:51
-
-
Save tzmartin/3139501 to your computer and use it in GitHub Desktop.
Roll your own reverse/forward geolocator in Titanium
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
/* Roll your own reverse/forward geolocator | |
* | |
* YQL | |
*/ | |
Titanium.Yahoo.yql('select * from yahoo.maps.findLocation where q="'+latitude+','+longitude+'" and gflags="R"',function(e) { | |
var woeid = e.data.ResultSet.Results.woeid; | |
Titanium.API.info(woeid); | |
}); | |
/* | |
* Google Maps API | |
*/ | |
function geocode(lat,lng){ | |
var urlLatLng="http://maps.google.com/maps/api/geocode/json?latlng="+lat+","+lng+"&sensor=true"; | |
//var urlAddress = "http://maps.google.com/maps/api/geocode/json?address=90210&sensor=true"; | |
xhr = Titanium.Network.createHTTPClient(); | |
xhr.open('GET',urlLatLng); | |
xhr.onload = function(){ | |
var json = this.responseText; | |
var items = eval('(' + json + ')'); | |
Ti.API.info('>ADDR found:'+ items.results[0].formatted_address); | |
adrlabel.text=items.results[0].formatted_address; | |
} | |
xhr.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment