10

I have made an app that gets an array of addresses from a web service and I want to map them. I know Apple left this out in MapKit, including only a reverse Geocoder. I was wondering what the best way to approach this problem was. Web Service? Google Maps API (How do API keys work?)? CloudMade?

What is your opinions on which service is fastest, easiest to use, and cheapest (hopefully free)?

conradev
  • 1,074
  • 1
  • 14
  • 31

5 Answers5

5

IANAL, but if the app you're building will be free, then I believe you can use the Google Maps API for free. It's limited to 15,000 geocoding requests per day, but according to the docs, that's tied to IP, not API key. You can get an API key immediately — no approval required. (If your app will not be freely available then you will have to sign up for Google Maps Premier.)

GMaps now has a REST-based geocoding API over HTTP (it used to be you had to use their JavaScript API, which was a pain on iPhone). It can return in JSON, which is trivial to parse using TouchJSON if you need the extra data, or CSV, which will be even easier if all you need is lat/lon. So, you can just create an object that conforms to the MKAnnotation protocol that will fetch the JSON/CSV from the API using an NSURLConnection or ASIHTTPRequest, parse it, and return the Point variable as the coordinate property and build your MapView as required.

Brock Batsell
  • 5,786
  • 1
  • 25
  • 27
  • That's not entirely true with mobile carriers, they often use gateway/proxies that finally brings the **same IP** for thousands users, which in highly crowded urban areas like where I am, Paris, France, goes over Google limits... and around 5pm, 503 errors for many users... – Vincent Guerci Apr 03 '11 at 18:57
5

Latest documentation regarding the usage of API keys with Google Maps Geocoding service API.

Get API Key

It can be referred to at the bottom of the page that you can use a generic unrestricted API key for testing in any platform.

As for iOS, I think we can just follow the Google Maps SDK documentation for iOS.

Jesse Armand
  • 1,842
  • 3
  • 17
  • 26
  • Thanks you so much! I would have never known that the new version came out. I have finally found a good solution. – conradev Apr 04 '10 at 13:03
  • Is there anyway to geocode multiple addresses in one request? I have an array of places I need to map, and the amount of places can climb into the fifties. I keep getting the error for "too many queries" after the around the tenth one – conradev Apr 05 '10 at 20:31
  • I'm not sure about that. I think you need to explore the Maps API regarding multiple requests. I'm quite doubtful they would accept subsequent requests. But, they may have a method to accept multiple addresses. I suggest to contact Google for your problem. – Jesse Armand Apr 10 '10 at 06:28
  • 2
    Note that according to the agreement with Google you are only allowed to use the Geocoding API together with a Google Map. Since it is Apple Maps nowdays you will be violating the agreement. – www.jensolsson.se Mar 25 '13 at 08:50
  • This answer was written in 2010. No Apple Maps that day. – Jesse Armand Mar 26 '13 at 03:11
  • So what's the answer now? What geocoding service is a viable option? MapQuest has a similar restriction. – samlandfried Nov 26 '18 at 20:48
4

Use Apple Geocoding API for this

http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/LocationAwarenessPG/UsingGeocoders/UsingGeocoders.html

"The CLGeocoder class provides services for converting between a coordinate (specified as a latitude and longitude) and the user-friendly representation of that coordinate. A user-friendly representation of the coordinate typically consists of the street, city, state, and country information corresponding to the given location, but it may also contain a relevant point of interest, landmarks, or other identifying information. A geocoder object is a single-shot object that works with a network-based service to look up placemark information for its specified coordinate value.

To use a geocoder object, create it and call one of its forward- or reverse-geocoding methods to begin the request. Reverse-geocoding requests take a latitude and longitude value and find a user-readable address. Forward-geocoding requests take a user-readable address and find the corresponding latitude and longitude value. Forward-geocoding requests may also return additional information about the specified location, such as a point of interest or building at that location. For both types of request, the results are returned using a CLPlacemark object. In the case of forward-geocoding requests, multiple placemark objects may be returned if the provided information yielded multiple possible locations."

CLGeoCoder geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"1 Infinite Loop"
     completionHandler:^(NSArray* placemarks, NSError* error){
         for (CLPlacemark* aPlacemark in placemarks)
         {
             // Process the placemark.
         }
}];
www.jensolsson.se
  • 3,023
  • 2
  • 35
  • 65
  • Thanks for the hint, I feel much more comfortable to use CLGeoCoder instead of the '3rd party' Google Maps approach! – Raffael May 31 '13 at 11:17
1

I use a "Restful WebService" for Reverse Geocoding using Google Maps and once I get the coordinates I store them in SQLite for later reference. The service returns a JSON string which I later parse in the iPhone.

Something like:

// Initialize call to REST Webservice
- (void) initCall
{
    // Service
    RESTClient *client = [[[RESTClient alloc] initWithDelegate:self] autorelease];
    NSString *serviceHost = @"http://www.site.com/service/maps";
    [client get:serviceHost];
    [serviceHost release];
}

- (void)RESTRequestDidSucceed:(RESTClient*)sender
{

        // Search
   NSString *data = [[[NSString alloc] init] autorelease];
   data = [[NSString alloc] initWithData:sender.receivedData encoding:NSUTF8StringEncoding];

   // Now you have the DATA in and NSString which you can pass as an argument to a method
   // something like

}
Michael D. Irizarry
  • 6,186
  • 5
  • 30
  • 35
0

According to both Google and Yahoo, their respective geocoding services DO NOT allow for "storage for future use." Unless I've misunderstood, you cannot store query results into any form of database. Otherwise it'd be really easy to just Google (now 50,000 requests per day).

ultrageek
  • 637
  • 1
  • 6
  • 13