zak
zak

Reputation: 39

center a mapkit map on a country

In my ipad app, i need to put a map of one country, so there are two parts in my question: 1: how to center the map on a country? 2: how to set the initial Scale of the map? thank you

Upvotes: 2

Views: 2865

Answers (2)

matrik
matrik

Reputation: 114

To get center coordinate of a country you can use geonames web service. For details check following question in stack overflow:

Need a list of all countries in the world, with a longitude and latitude coordinate

Upvotes: 1

dfmuir
dfmuir

Reputation: 2088

Ok you are going to first need to find the Lat/Lon coordinates of a point somewhere in the center of the country. Let's say you have the following defined:

MKMapView *mapView;
float latitude_coordinate;
float longitude_coordinate;
float latMeters;
float lonMeters;


CLLocationCoordinate2D coordinates = CLLocationCoordinate2DMake(latitude,longitude);
MKCoordinateRegion region = MKCoordinateRegionMake(coordinates, latMeters, lonMeters)
[mapView setRegion:region animated:NO];

latMeters/lonMeters are the number of meters wide and high for the region that the map will display.

Upvotes: 3

Related Questions