Rob88991 Rob88991 - 1 year ago 94
iOS Question

Appcelerator - Getting geolocation information and turning into a URL

I'm still very new to appcelerator but I'm trying to do a small experiment with geolocation. I have some code similar to below, which returns the long and lat to the console. What I would like to is get the long and lat and append them to a URL, e.g

I've tried creating a simple alert to show me the current location in the but all it says is Alert: [object GeolocationModule].

Could somebody point me in the right direction so I can learn some more? Thank you

if (Ti.Geolocation.locationServicesEnabled) {
Titanium.Geolocation.purpose = 'Get Current Location';
Titanium.Geolocation.getCurrentPosition(function(e) {
if (e.error) {
Ti.API.error('Error: ' + e.error);
} else {;
} else {

alert('Please enable location services');


This is how you need to follow the API documentation:

You can have a look at the LocationResults page:!/api/LocationResults which leads you to LocationCoordinates:!/api/LocationCoordinates

There you can see, that you can use e.coords.latitude or longitude to get the values. Or have a look at the console output. It should show you a JSON output with the key-value pairs.

Once you have the values you can create a HTTP request (demo:!/guide/HTTPClient_and_the_Request_Lifecycle) and open your page:

var url = ""+e.coords.longitude+"/"+e.coords.latitude;
var xhr = Ti.Network.createHTTPClient({
    onload: function(e) {
        // this function is called when data is returned from the server and available for use
        // this.responseText holds the raw text return of the message (used for text/JSON)
        // this.responseXML holds any returned XML (including SOAP)
        // this.responseData holds any returned binary data
    onerror: function(e) {
        // this function is called when an error occurs, including a timeout
    timeout:5000  /* in milliseconds */
});"GET", url);
xhr.send();  // request is actually sent with this statement

or if you plan to use more request have a look at RESTe ( which is an awesome library that makes it easy to create API requests