Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Map & Location Question

I'm hoping it a gap in the documentation. I'm looking at the docs for Titanium.Geolocation and Titanium.Map and have not been able to figure it out.

I have a list of sites (cordinates in terms of Lat & Long). I need to use my current location to deternine which site I'm closest to. Any ideas? Thx.

— asked April 7th 2010 by Conrad McLean
  • android map geolocation

3 Answers

  • I'm no genius with regards to map stuff, but I think what you are looking for isn't really covered by the Ti map API (or any other eg Google API). Basically you need to do some simple math to compare your coordinates against your list and determine which has the shortest distance. If you poke around the Google Maps API groups you can find what you need (I've seen it pop up quite a bit).

    For example, googling this: "calculate distance between latitude longitude" returns this: http://www.movable-type.co.uk/scripts/latlong.html which should be what you need?

    — answered April 7th 2010 by karlo kilayko
  • The iPhone SDK supports such things as calculating distance between points, reverse geolocation lookup, etc. According to the docs, it doesn't look like these have been implemented in Titanium yet.

    — answered April 7th 2010 by Ryan Huff
  • This might be old, but this function works fine, just sub in your lat/lons…it doesnt take routing into effect, just the direct line.

    var dist = Math.sin(radlat1) Math.sin(radlat2) + Math.cos(radlat1) Math.cos(radlat2) Math.cos(radtheta);
    dist = Math.acos(dist);
    dist = dist
    dist = dist 60 1.1515;
    if (unit=="K") {
    dist = dist * 1.609344;

    if (unit=="N") {
         dist = dist * 0.8684;
    return dist;

    var x=distance(30.5166667,-86.4822222,30.7619444, -86.5705556,"N");

    — answered November 6th 2010 by Josh Lewis
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.