Ios – How to set location in map in IOS

iosios5mapkitobjective c

I am trying to learn MAP for iPhone.

What I have right now is below.

  1. Created new project
  2. Added framework for MAP
  3. Brought map object on storyboard (UIViewController)
  4. Run the project.

What I see is, its not showing any location. When I change location in xcode, it shows me the dot at location.

What I wanted is, by default it should show me the PIN to the location that I will set by using latitude and longitude. Also the map should be zoomed. What I meant by zoom is, I should see the location with lets say 13 zoom effect. Right now, I see world map on screen.

Any idea how to get this done?

Best Answer

You can center your map around a location by doing something like this:

    MKCoordinateRegion mapRegion;
    mapRegion.center.latitude = aLatitude;
    mapRegion.center.longitude = aLongitude;
    mapRegion.span.latitudeDelta = 0.005;
    mapRegion.span.longitudeDelta = 0.005;
    self.mapView.region = mapRegion;

Use the span values to determine the zoom level you want.

In order to show a pin you need to create an annotation with the coordinates of your location and then add it to the map.

Also, check out this tutorial.. http://www.raywenderlich.com/2847/introduction-to-mapkit-on-ios-tutorial