如何根据用户的选择将地图的焦点设置到特定国家/地区?

发布于 2024-11-28 06:50:29 字数 85 浏览 2 评论 0原文

在我的应用程序中,用户试图查看给定国家/地区的活动数量。假设他想看到美国地区的所有活动,那么我应该如何将焦点集中在美国而不是全世界。

谢谢,

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静谧 2024-12-05 06:50:29

使用以下方法:

-(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];
}

并在任何情况下通过以下行调用此方法:

[self setMapCenter:countryLocation.coordinate];

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];
晚风撩人 2024-12-05 06:50:29

您所要做的就是找出您希望地图以哪个坐标为中心,以及地图大小有多大,这样就可以了。我不确定是否有任何在线资源具有每个国家/地区的通用点,但您可以在谷歌上查找它们,并制作一个字典,其中包含每个国家/地区的所有中心点和尺寸,名称为国家是这些问题的关键。然后,当用户选择一个国家/地区时,您可以在字典中查找它,并将这些中心点和尺寸加载到地图中,这将显示该国家/地区。希望有帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文