Search code examples
iosgpslocation

Request routing on iPhone/iPod without GPS


I want to build an iPhone App that should contact a server that is nearest to its location. The app itself knows where the servers are located and it should find out which one to choose.

Because I expect many users with an iPod touch I can't use GPS to do this.

On Stack Overflow and ServerFault I found this possible solutions:

  1. Use Anycast technology to route users => I can't use this method because the device itself should route the requests and know where they are going.

  2. Get country code and use the Google Directions API to determinate which server is nearest.

  3. Get location by IP (GeoDNS etc.) and do the same (see above).

Method 2 seems good but I have three questions to that:

  1. The API sends me the whole route from point x to point z. I just want to have distance. Is there a way to do that?

  2. Google says they have a usage limit of 2,500 request per day. How do they control that? By IP? I ask this because they say you don't have to use an API key - how do they control then?

  3. Is is a good idea to use Google without having any trouble later? My app itself will be free but I'll have In-App Purchases in it. Does that matter?

I hope somebody has experience in this.


Solution

  • In many cases, iOS will still return a location when requested on devices without GPS. Remember, the first generation iPhone didn't have GPS, but could still do location based services. iOS will use a number of techniques (IP geolocation, skyhook, etc) to find the location of a user, in addition to GPS.

    Anyway, to answer some of your questions:

    The 2,500 requests per day is per end user, or typically per IP address. So you shouldn't need to worry about getting capped. You should however be aware that you need to display a Google Map to use the API, so if you're using their API and not using a mapView you may have an issue.

    I'm not entirely sure why you would need to use the Google directions API in the first place. If you can get lat/lon coordinates of both the user's current location and your servers you can just use iOS's built-in CoreLocation methods to get the distance between them, and decide accordingly ([CLLocation getDistanceFromLocation]).