Scalable solution for geocoding on iOS - ios

I'm working on an iOS app that pulls events from Google Calendar and subsequently generates pins on a map for each event (based on what the event creator fills in for "Location"). The user can select a date range (today, this week, this month, etc.) and see all the events taking place near them over that period.
Problem 1: The app is for my local university, so a majority of the locations will be buildings on campus. These buildings have inconsistent addresses that are often difficult to find, so it would be good if the location "Foo Hall" would result in a pin on that building. Google Maps is capable of doing this, however Apple Maps has no knowledge of the buildings on my school campus.
Problem 2: In an ideal situation, thousands of students would be using this app. Each time they open the app, they could be viewing dozens of pins. Therefore, I'm worried that I may be pushing the limits imposed by Google's geocoding API (definitely the 2500 request limit, and maybe even the 100,000 request limit for the Business API).
So my question is... what would be the best solution for these two problems? Should I create a local database for building names and map them to coordinates? Or is there a way I can overcome the limitations of Google's Geocoding API? Is there a better solution I'm not thinking of?
Thanks for any help!

I would use latitude and longitude coordinates for the buildings and allow for people to add locations to the database if they are meeting somewhere that you have not added already. This way, the pins will drop in the center of the building if you want them to, because you are not relying on an address or on looking up a building name. You simply know that "Foo Hall" is at X latt. and Y long. And if someone selects "Foo Hall" or sees an event at "Foo Hall" there is a perfectly placed pin right in the middle of it on the map. I don't think you need to worry as much about the geocoding API if you are using hardcoded locations for the buildings either, because you won't have to be polling Google to get the building locations.
I would also use some sort of server to store the building locations so they can be updated or added to, either by you or by the users.
That's how I would handle it, good luck!

Related

MKLocalSearchCompleter adding region does not skew results

I'm currently using MapKit's MKLocalSearchCompleter to provide an autocomplete-like functionality for users searching for a location in my iOS app, however I'm running into some serious issues with the results I'm getting back. To be more specific, my app is dealing with location information in and around Central New York and I am really trying to cater the results to locations/addresses within New York state. But for some reason typing in so much as one word will in most instances yield results from as far away as Australia.
MKLocalSearchCompleter provides a region attribute for influencing the object to return results near a specified region, but even that doesn't seem to be helping much.
Is there anything more I can do? Or should I consider calling it quits and moving to Google's Maps API at this point? I know Apple Maps has been notorious for erring on the side of low quality, but I didn't think I'd be subjected to only getting location results in Texas and Australia after telling their API to stick New York...

Offline reverse geocoding on iOS

There are lots of existing questions relating to this issue, but I have looked at as many of them as I could find and did not get an answer.
I'm trying to perform an offline reverse geocoding lookup on iOS based on a latitude and longitude. I'd like to be able to provide a latitude and longitude, and be provided with the country in which that point lies. I can do this with Geonames (such as: http://api.geonames.org/countryCode?lat=45.03&lng=8.2&username=demo), but I need a similar ability offline, without Internet functionality on the device.
CLLocation does not provide offline services that work reliably enough for what I'm doing, it relies on caches made while you were previously online, etc. Messy.
I've tried this: https://github.com/drodriguez/reversegeocoding but haven't had any luck, it requires some slightly complex / confusing Terminal installations using something called Thor which I've never heard of, and was throwing up a variety of errors, so I bailed on it.
I've found a few downloadable maps, but these seem to be even more complicated, and worryingly, hundreds of megabytes or even gigabytes in size – much beyond the scope of an iOS app. I only need countries, nothing smaller than that (cities, streets, locations, etc.) so I think I should be able to get a much smaller file.
So my key question is: is there some pre-existing database or tool, preferably with iOS support, that I can feed a latitude/longitude, and get a country? And, if not, what steps should I take to get such functionality working on my own?
Thanks in advance.
ReverseGeocodeCountry is a simple lightweight offline country reverse geocoder for iOS, it has a static JSON file with country polygon data that is used to reverse geocode any lat/lng:
https://github.com/krisrak/ios-offline-reverse-geocode-country
The "Countries of the World" is a .csv text file with countries, coordinates, localised country names, capitals and other information. It seems to be free to use. You just have to import it into an SQLite database.
Edit Just noticed you want reverse geocoding. The database would only be good for forward geocoding.
You can download shapefiles for all countries at http://www.gadm.org/download. If you download a .kmz, you can unpack it to a list of coordinates for the borders. You could probably take every 5th or 10th coordinate to get smaller size (with less accuracy).
Just in case I can suggest another good written offline geocoding library.
https://github.com/Alterplay/APOfflineReverseGeocoding

Mapkit. Getting nearby places from a server and possibly caching them (e.g. for offline use)

I am developing iOS 5 app which I want to communicate with server providing information about the nearby places for a given location: places locations and annotations. I want to use MapKit to populate my map with this information.
I didn't find any straightforward information regarding the following questions:
Does MapKit has tiles functionality (Google Maps way) out-of-the-box and do I need to work on it additionally, if not?
What is the best practice of retrieving places information (markers positions and annotations) from server?
Is it possible to cache this information so an user can see the nearby places of "his city" in offline mode?
Actually questions 2 and 3 are interrelated: they both address the problem of not retrieving an information (locations + annotations) that is already on map multiple times.
Hopefully I am not overlooking something obvious here.
Thanks!
Update 1: (Regarding places, not maps) More specifically I am interested in, how should I create a "hand-crafted" logical tiles for regions containing the places I fetch from the server, so they would not require refetching themselves when user scrolls the map? I know I can dive into implementing this functionality myself. For example, should I write the places just fetched to a local storage using Core Data immediately after fetching them or organize some queue? Or how could I know when I need to perform a request about the specific region on server and when I just fetch local data that is already on the device? I just want to know, are there any recommended approaches, best practices? Hopefully, I wrote it clear here.
Update 2: I am wondering about best practices here (links, example) not to start creating all this (points 2+3) from scratch. Are there any frameworks incapsulating this or good tutorials?
#Stanislaw - We have implemented the functionality you describe in an app called PreventConnect for one of our clients. The client already had some data stored out in a Google Fusion table. We extended their existing solution by adding another Google Fusion table which stores the geocoordinates for a number of locations. All this being said, to answer your questions...
1) The map portion itself is pretty out of the box, the tiles and what not, but you'll need to do some coding to get zoom extents, pin drops, annotations, and things like that working the way you expect them to work.
2) We found the Google Fusion solution to be quite effective. If you don't want to use Google Fusion there are other cloud database providers like StackMob, database.com, and many others. Google is free and they have an iOS SDK that makes communicating with Google Fusion pretty simple.
3) Absolutely! We cache much of the data in a Core Data store locally on the device. This greatly improves performance and responsiveness.
Time to write a solid answer to this my question (I could have it written a year ago but somehow I lost it from my mind).
Does MapKit has tiles functionality (Google Maps way) out-of-the-box and do I need to work on it additionally, if not?
The answer is yes: MapKit does have it. The keywords here are overlays (MKOverlay, MKOverlayView and others). See my another answer.
See also:
WWDC 2010 Session: Customizing Maps with Overlays,
Apple-WWDC10-TileMap.
What is the best practice of retrieving places information (markers positions and annotations) from server?
Actually since then I didn't learn a lot about "best practices" - unfortunately, nobody told me about them :( - that is why I will describe "my practices".
First of all, there are two strategies of populating a MapKit map with places:
The first strategy is about populating your map with the places by demand: imagine you want to display and see all places nearby (for example, no more than 1km from current user location) - this approach assumes that you ask your server only the places for the box you are being interested in. It means something like: "if I am in Berlin (and I expect 200 places for Berlin), why should I ever fetch the places from Russia, Japan, ... (10000+ places)".
This approach leads to relying on "tiles" functionality that question N1 address: Google maps and Apple maps are usually drawn using 'tiles' so for your "Berlin" portion of map you rely on corresponding "Berlin" tiles that are drawn by MKMapView - you use their dimensions, to ask your server only the places within the "Berlin" box (see my linked answer and the demo app there).
Initially this was the approach I've used and my implementation worked perfectly but later I was pushed to use second approach (see below) because the problem of clustering appeared.
The second strategy is to fetch all the places at once (yeah, all this 10000+ or more) and use Core Data to fetch the places needed for the visible portions of map your are interested in.
Second approach means, that during the first run you send your server a request to fetch all places (I have about 2000 in my app). Important here is that you restrict the fields you fetch to only geo-ones that you really need for your map: id, latitude, longitude.
This 'fetch-all' fetch has a significant impact on my app's first start time (On "the oldest" iPhone 4, I have near 700ms for the whole Fetch + Parse-JSON-into-Core-Data process, and extensive benchmarks show me that it is Core Data and its inserts is a bottleneck) but then you have all the essential geo-info about your places on your device.
Note, that whatever strategy you use, you should do a process of fetching these geo-points efficiently:
Imagine Core Data entity Place which has the following fields structure (preudo-Objective-C code):
// Unique identificator
NSNumber *id,
// Geo info
NSNumber *latitude,
NSNumber *longitude,
// The rest "heavy" info
NSString *name,
NSString *shortDescription,
NSString *detailedDescription, etc
Fetching places efficiently means that you ask only your place records geo-data from your server to make the process of this mirroring as fast as possible.
See also this hot topic: Improve process of mirroring server database to a client database via JSON?.
The clustering problem is out of scope of this question but is still very relevant and affects the whole algorithm you use for the whole proces - the only note I will leave here is that all the current existing clustering solutions will require you to use second strategy - you must have all the places prepared before you run into the clustering algorithms that will organize your places on a map - it means that if you decide to use clustering you must use strategy #2.
Relevant links on clustering:
WWDC 2011 Session: Visualizing Information Geographically with MapKit,
How To Efficiently Display Large Amounts of Data on iOS Maps,
kingpin - Open-source clustering solution: performant and easy-to-use.
Is it possible to cache this information so an user can see the nearby places of "his city" in offline mode?
Yes, both strategies do this: the first one caches the places you see on your map - if you observed Berlin's portion of map you will have Berlin part cached...
When using the second strategy: you will have all essential geo-information about your places cached and ready to be drawn on a map in offline mode (assuming that MapKit cached the map images of regions you browse in offline mode).

Get nearest business name/type by address or GPS coordinate

I'm writing an iOS application and it would be very handy to know the way to find a nearest business name (and especially business type, such as restaurant/hotel/store etc.) by a GPS coordinate, or at least by an address.
So just curious, is there such API/Web service out there?
Yes
Bing
Google Places
Yahoo Geo Technologies
I'm sure there are loads more to be found with a quick google
OK, it seems like I have to answer my own question. I didn't try it out in code, but the answer is here:
http://code.google.com/apis/maps/documentation/places/
Unfortunately there seems to be a cap on how many times Google places API can be called (for free), i.e. 1000 times per day (for the same API_key.)

Is the Map Rails Kit worth the money?

http://railskits.com/map/
Would you like to launch your own
google map mashup? Need a way to
easily get data onto a map, but don’t
want to have to dig through piles of
poorly documented Google Maps
javascript code?
The Map Rails Kit allows you to deploy
a map mashup instantly. It extracts
all the Google Maps implementation
details, organizes all the
customizations into an easy to use
config file, and reimplements the map
controls, bubbles, and markers so your
app looks unique.
Populating your map with markers
consists of working with a few simple
ActiveRecord models so it’s amazingly
easy to get started. Create marker
records with titles, bubble content,
and location. If you specify just an
address to your markers, your markers
will be automatically geocoded for
you. You can even add tens of
thousands of markers to your maps
easily, and they’ll dynamically load
onto the map only when they are
currently in view as your users
navigate the map.
The Kit includes all the usability
polish that your users would expect in
a commercial map mashup. Their current
map settings are always saved via
session so when they come back to the
page later on, they’re right where
they left off before. For new
visitors, we support hooking into an
ip2location service in order to
initialize their current position. So
they immediately see their current
spot on the map, and can begin
interacting with it.
This Kit was authored by Jacques
Crocker.
This is kind of subjective, but I don't find the Google Maps API nearly as daunting as the blurb makes it out to be. I don't think I'd pay half a grand for an API to the Maps API — especially since you can buy a whole book on the topic for like $15 even if you find Google's docs lacking.
This guy doesn't even make it clear what it is he's selling. He makes the features of using the google maps API with Rails sound more difficult than entire feature set of Google maps itself.
There are plenty of other plugins and/or gems available that do more or less the same thing with slightly more effort involved and the book of course (possibly more than one at this point).
If you want a turnkey solution for stacks of money, .NET or some more commercial platform will have more options. I would avoid using this guys solutions out of selfishness, if he does well they'll be others with more colorful marketing making such grand solutions. After which Google will be clogged with them and we'll have to wade through dozens of such spectacular offerings to find the better, albeit less polished (less advertised) open source versions.
Are there any good googlemaps plugins for rails?

Resources