I have a metro application (WinJS) which gets user coordinates, this is the code:
var loc = null;
function getloc() {
if (loc == null) {loc = new Windows.Devices.Geolocation.Geolocator();}
if (loc != null) {loc.getGeopositionAsync().then(getPositionHandler, errorHandler);}
}
function getPositionHandler(pos) {
signatureAddressStrokeText.value = pos.coordinate.latitude + "," + pos.coordinate.longitude;
}
function errorHandler(e) {
signatureAddressStrokeText.value = e.message + getStatusString(loc.locationStatus);
}
function getStatusString(locStatus) {
switch (locStatus) {
case Windows.Devices.Geolocation.PositionStatus.ready:
return "Location is available.";
break;
case Windows.Devices.Geolocation.PositionStatus.initializing:
// This status indicates that a GPS is still acquiring a fix
return "A GPS device is still initializing.";
break;
case Windows.Devices.Geolocation.PositionStatus.noData:
// No location data is currently available
return "Data from location services is currently unavailable.";
break;
case Windows.Devices.Geolocation.PositionStatus.disabled:
// The app doesn't have permission to access location,
// either because location has been turned off.
return "Your location is currently turned off. " +
"Change your settings through the Settings charm " +
" to turn it back on.";
break;
case Windows.Devices.Geolocation.PositionStatus.notInitialized:
// This status indicates that the app has not yet requested
// location data by calling GetGeolocationAsync() or
// registering an event handler for the positionChanged event.
return "Location status is not initialized because " +
"the app has not requested location data.";
break;
case Windows.Devices.Geolocation.PositionStatus.notAvailable:
// Location is not available on this version of Windows
return "You do not have the required location services " +
"present on your system.";
break;
default:
break;
}
}
this prints on my textField (signatureAddressStrokeText) the coordinates, but I want to get location address string by using these coordinates, I need to make a reverse geocoding for achieve that, but so far I haven't found anything about this topic, how to make reverse geocoding on WinJS??
thanks in advance for the support
EDIT: I could make it work thanks to the Link Provided by WiredPrairie, this is the code generated by me:
function webServiceReverseGeolocation(latitude, longitude) {
return new WinJS.Promise(function (complete, error) {
var options = {
url: "http://maps.googleapis.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&sensor=true",
responseType: "document"
};
WinJS.Promise.timeout(constants.WEB_SERV_TIMEOUT, WinJS.xhr(options)).then(
function (request) {
var doc = request.responseXML.documentElement;
var output = doc.getElementsByTagName("formatted_address");
signatureAddressStrokeText.value = output[0].textContent;
complete(true);
},
function (error) {
signatureAddressStrokeText.value = "Error getting location: " + error.status + " " + error.statusText, "Status";
complete(false);
},
function (progress) {
signatureAddressStrokeText.value = "Getting current address from coordinates provided by GPS device... please wait";
}
);
});
}
basicly is a function, requires longitude and latitude, and this prints on my textField (signatureAddressStrokeText) full address obtained from google XML response