Skip to content

designbymind/Ti.Geocoder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ti.Geocoder

The Ti.Geocoder module provides access to the native geo decoders on Android and iOS.

Before you start

* You need Titanium 3.5.0.GA or greater. * This module has only been tested on iOS7+ and Android 4+

tiapp.xml update

If you plan to support iOS you will need to add the NSLocationAlwaysUsageDescription or NSLocationUsageDescription entry in your tiapp.xml as shown below. The string value displays the purpose message that the user will be alerted when GPS access is requested.

    <ios>
        <plist>
            <dict>
                <key>NSLocationUsageDescription</key>
                <string>Will do something awesome when the app is open</string>
                <key>NSLocationAlwaysUsageDescription</key>
                <string>Will do something awesome in the background</string>
            </dict>
        </plist>
    </ios>

Setup

  • Android dist folder
  • iOS dist folder
  • Install the Ti.Geocoder module. If you need help here is a "How To" guide.
  • You can now use the module via the commonJS require method, example shown below.

//Add the core module into your project
var geocoder = require('ti.geocoder');

Now we have the module installed and avoid in our project we can start to use the components, see the feature guide below for details.

Methods

isSupported

Indicates of the module is supported

Method returns true or false

getCurrentPlace

Retrieves the last known place information (address) from the device.

Parameters

  • callback : Function to invoke on success or failure of obtaining the current place information.

Sample


//Add the core module into your project
var geocoder = require('ti.geocoder');

function resultsCallback(e){
	Ti.API.info("Did it work? " + e.success);
	if(e.success){
		Ti.API.info("It worked");
	}	

	var test = JSON.stringify(e);
	Ti.API.info("Results stringified" + test);
};

Ti.API.info("Let's get the places information (address) for our current location");
Ti.API.info("We make our call and provide a callback then wait...");
geocoder.getCurrentPlace(resultsCallback);

reverseGeocoder

Tries to resolve a location to an address.

The callback receives a results object. If the request is successful, the object includes one or more addresses that are possible matches for the requested coordinates.

Parameters:

  • latitude : Number
  • longitude : Number
  • callback : Function to invoke on success or failure.

All three parameters are required.

Sample


//Add the core module into your project
var geocoder = require('ti.geocoder');

function reverseGeoCallback(e){
	Ti.API.info("Did it work? " + e.success);
	if(e.success){
		Ti.API.info("This is the number of places found, it can return many depending on your search");
		Ti.API.info("Places found = " + e.placeCount);	
	}	

	var test = JSON.stringify(e);
	Ti.API.info("Forward Results stringified" + test);
};

Ti.API.info("Let's now try to do a reverse Geo lookup using the Time Square coordinates");
Ti.API.info("Pass in our coordinates and callback then wait...");
geocoder.reverseGeocoder(40.75773,-73.985708,reverseGeoCallback);

forwardGeocoder

Resolves an address to a location. Parameters:

  • Address : String
  • callback : Function to invoke on success or failure.

Both parameters are required.

Sample


//Add the core module into your project
var geocoder = require('ti.geocoder');

function forwardGeoCallback(e){
	Ti.API.info("Did it work? " + e.success);
	if(e.success){
		Ti.API.info("This is the number of places found, it can return many depending on your search");
		Ti.API.info("Places found = " + e.placeCount);	
	}	

	var test = JSON.stringify(e);
	Ti.API.info("Forward Results stringified" + test);
};

Ti.API.info("Now let's do some forward Geo and lookup the address for Appcelerator HQ");
var address="440 N. Bernardo Avenue Mountain View, CA";

Ti.API.info("We call the forward Geocoder providing an address and callback");
Ti.API.info("Now we wait for the lookup");
geocoder.forwardGeocoder(address,forwardGeoCallback);

Contributing

The Ti.Geocoder is a open source project. Please help us by contributing to documentation, reporting bugs, forking the code to add features or make bug fixes, etc.

Learn More

Twitter

Please consider following the @bencoding Twitter for updates and more about Titanium.

Blog

For module updates, Titanium tutorials and more please check out my blog at bencoding.com.

About

Native Geocoders for Titanium mobile

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 37.8%
  • Objective-C 33.8%
  • Python 15.6%
  • JavaScript 12.8%