Ashutosh
Ashutosh

Reputation: 5742

How to set the focus of my Map on to specific country based upon user's selection?

In my app user is trying to see the number of activity in a given country. Let's say if he wants to see all the activities in US region so how should i set the focus on US only and not on the whole world.

Thanks,

Upvotes: 0

Views: 646

Answers (2)

rptwsthi
rptwsthi

Reputation: 10182

Use Following Method:

-(void)setMapCenter:(CLLocationCoordinate2D)location
{
NSLog(@"Current Location : %f, %f",location.latitude,location.longitude);
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.01;
span.longitudeDelta=0.01;
region.span=span;
//location.latitude=(float *)(self.appDelegate.currentLocationLatitude);
//location.latitude=self.appDelegate.currentLocationLongitude;
region.center=location;
[self._mapView setRegion:region animated:TRUE];
[self._mapView regionThatFits:region];
}

And Call this method through following line in any event:

[self setMapCenter:countryLocation.coordinate];

Upvotes: 3

msgambel
msgambel

Reputation: 7340

All you have to do is figure out the coordinates that you want the map to centre on, and how large the map size is, and that will work. I'm not sure if there are any online resources which have generic points for each country, but you could look them up on google, and the make a dictionary which holds all of those centre points and sizes for each country, with the name of the country being the key for those points. Then, when the user selects a country, you look it up in the dictionary, and load those centre points and sizes into your map, and that will display that country. Hope that helps!

Upvotes: 1

Related Questions