Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - MapKit - Searching locations and moving annotations

I want to make an app that partially mimics some of the behavior the standard map application has. This has proven difficult. First of all, I don't understand how you make annotations movable. How exactly do you do this?

Second: how do you search for locations?

like image 521
quano Avatar asked May 11 '10 17:05

quano


2 Answers

Moving annotations

I'm assuming you're after the behavior of Maps.app where you tap and hold on to a pin to move it around freely. As far as I know, there is no built in way of moving annotations around. Since annotations are subclasses of UIView though, you can draw them where and how you'd like. You could for example detect a tap-n-hold on the annotation, and when "unlocked" change the centerOffset value of your annotation to move it around with the touch. When the user lets go of the the view, you can note the position on the screen, and use the MKMapView method convertPoint:toCoordinateFromView: to get the coordinates that the pin was released.

Search for location

What you are looking for is called Forward Geocoding. Unfortunately, MapKit only comes with Reverse Geocoding (the process of converting GPS coordinates to country/city/street/etc). There is, however, several alternatives. Here's a few ways:

  • http://code.google.com/apis/maps/documentation/geocoding/index.html
  • http://cloudmade.com/products/iphone-sdk
  • http://www.geonames.org/export/web-services.html
  • http://developer.yahoo.com/maps/rest/V1/geocode.html

Note that many geocoding APIs are licensed under Creative Commons, or similar licenses.

like image 180
alleus Avatar answered Oct 03 '22 07:10

alleus


You should be able to get drag-and-drop annotations going with the help of this blog post. I used it to do the same thing, and it was pretty simple to get going.

MapKit annotation drag and drop with callout info update

like image 32
Ben Williams Avatar answered Oct 03 '22 07:10

Ben Williams