Coder Social home page Coder Social logo

ti.geocoder's Introduction

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.

ti.geocoder's People

Contributors

benbahrenburg avatar stephenfeather avatar

Stargazers

Romeo Manzur avatar Jason David Miller avatar Nick avatar  avatar Yevgen Sukharenko avatar jakkrokk avatar Manjunath (MJ) avatar  avatar Abdulatif Henno avatar lzw avatar Konstantin Büschel avatar Mahmoud Kamal avatar Manuel Lehner avatar Vinicius Oliveira avatar  avatar  avatar

Watchers

 avatar  avatar James Cloos avatar Danny avatar  avatar dlewis23 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.