- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有这段代码:
- (void)viewDidLoad
{
[super viewDidLoad];
CLLocationCoordinate2D userLocation = CLLocationCoordinate2DMake(48.9793946200, 2.4726272850);
CLLocationDistance dist1 = 636.9887048804;
CLLocationDistance dist2 = 900.8380655203;
CLLocationDistance dist = dist1;
[self.myMapView setRegion:MKCoordinateRegionMakeWithDistance(userLocation, dist, dist) animated:YES];
// TEST
// ------------------------------------------------------------
MKCoordinateRegion region = self.myMapView.region;
CLLocationDegrees lat = region.center.latitude;
CLLocationDegrees lon = region.center.longitude - region.span.longitudeDelta/2;
CLLocation *west = [[[CLLocation alloc] initWithLatitude:lat longitude:lon] autorelease];
NSLog(@"User location: lat : %.10lf long : %.10lf", userLocation.latitude, userLocation.longitude);
NSLog(@"distance set: %.10lfm", dist);
NSLog(@"center: lat : %.8lf long : %.8lf", region.center.latitude, region.center.longitude);
CLLocation* centerRegion = [[[CLLocation alloc] initWithLatitude:region.center.latitude longitude:region.center.longitude] autorelease];
NSLog(@"distance to western boundary: %.2lfm", [centerRegion distanceFromLocation:west]);
lat = region.center.latitude - region.span.latitudeDelta/2 ;
lon = region.center.longitude;
CLLocation *north = [[[CLLocation alloc] initWithLatitude:lat longitude:lon] autorelease];
NSLog(@"distance to western boundary: %.2lfm", [centerRegion distanceFromLocation:north]);
// ------------------------------------------------------------
}
当设置 dist = dist1 时,会给出:
User location: lat : 48.9793946200 long : 2.4726272850
distance set: 636.9887048804m
center: lat : 48.97937199 long : 2.47269630
distance to western boundary: 500.44m
distance to western boundary: 650.57m
当设置 dist = dist2 时,会给出:
User location: lat : 48.9793946200 long : 2.4726272850
distance set: 900.8380655203m
center: lat : 48.97937199 long : 2.47269630
distance to western boundary: 500.44m
distance to western boundary: 650.57m
这里有什么问题?为什么我有相同的显示器但有 2 个不同的距离?
最后一个问题:我如何才能确保在 map 上至少显示水平和垂直视觉(当然有或没有动画)所需的仪表?
最佳答案
如果我理解正确,您想告诉 mapView“给我一张横跨 636 米的 map ”或“给我一张横跨 900 米的 map ”。但是 map 为您提供了这两者的相同距离。
当您设置 map 区域时,您通常不会准确返回您要求的内容,而是最适合的。 map View 查看您请求的区域,然后在其中创建一个适合您所在区域的区域。问题是 map View 不会精确缩放到您请求的区域,它会找到允许您所有区域可见的最高缩放级别。它不会使用中间缩放级别。这就是为什么当您使用 setRegion:
时 map 总是看起来清晰。您可以通过捏合或捏合来手动设置中间缩放级别,但不能(据我所知)以编程方式设置。
另请注意, map View 可能会更改您传递给它的实际 region
变量。这是文档:
When setting a new region, the map may adjust the value in the region parameter so that it fits the visible area of the map precisely. This is normal and is done to ensure that the value in the region property always reflects the visible portion of the map. However, it does mean that if you get the value of that property right after calling this method, the returned value may not match the value you set. (You can use the regionThatFits: method to determine the region that will actually be set by the map.)
您可以通过记录您提供的区域和 map View 实际设置的区域来查看区域的差异(尽管我没有看到传递的 myRegion
更改):
MKCoordinateRegion myRegion = MKCoordinateRegionMakeWithDistance(userLocation, dist, dist);
NSLog(@"Passed: %f %f", myRegion.span.latitudeDelta, myRegion.span.longitudeDelta);
[self.mapView setRegion:myRegion animated:YES];
NSLog(@"Passed 2: %f %f", myRegion.span.latitudeDelta, myRegion.span.longitudeDelta);
NSLog(@"Set: %f %f", mapView.region.span.latitudeDelta, mapView.region.span.longitudeDelta);
> Passed: 0.005728 0.008702
> Passed 2: 0.005728 0.008702
> Set: 0.012957 0.013733
如果您将距离提高到 1200 米,您将能够看到下一个缩放级别。
顺便说一句,您的代码中有一个小错误:
NSLog(@"distance to western boundary: %.2lfm", [centerRegion distanceFromLocation:north]);
应该是
NSLog(@"distance to northern boundary: %.2lfm", [centerRegion distanceFromLocation:north]);
关于iphone - MKCoordinateRegionMakeWithDistance 没有在 MapView 上设置正确的区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7299747/
我更新了 Android Google Maps v2 示例应用程序中的 RawMapViewDemoActivity.java 以编程方式创建 MapView,但未显示 map 。我只是得到一个空白
我需要一个禁用所有手势的 MapView。它基本上只是 fragment 中的一个小 View ,当您按下它时,它会转到 LocationPickerFragment。我认为我没有以正确的方式做这件事
我试图通过函数在 mapView 上放置一些注释,但 mapView 在调试器中显示为 nil。我从不同的类调用下面的函数,调用似乎通过设置一些断点来工作。它只是在尝试将注释数组添加到 mapView
我刚刚构建了一个 swift 应用程序,它从 dynamoDB 获取 data+coords 并将其放到 ios mapkit 上。有两组坐标:一组用于当前用户位置,一组来自dynamoDB。我希望这
我在屏幕的一角有一个 Google map View 。我想添加一个事件,使其通过 map 界面上的按钮进入全屏,然后再次使用相同的按钮进入小屏幕。有什么想法吗?? 安卓 v4.0.4谷歌地图 API
问题 我有一个包含全屏 MKMapView 的 View 。 MapView 的下半部分覆盖有具有半透明单元格的 TableView,以便 map 显示。 当我以注释坐标为中心时,例如当前位置,注释
我如何从 React-Native 中 MapView 组件的纬度和经度值计算 delta-latitude 和 delta-longitude 值。谢谢你 最佳答案 如果您有一个坐标数组并且您想要一
为什么 CameraUpdateFactory 类在我的项目中不起作用? 如果执行以下命令,应用程序会崩溃: CameraUpdate pino= CameraUpdateFactory.newLat
我搜索了这个问题,发现了一些关于相同但不知道如何解决问题的 stackoverflow 问题。 我创建了一个 Activity ,我想添加一个非常小的 map View (例如 140w X 70h)
我在 android 市场上有一个应用程序,它使用 mapview 来显示一些位置。这在我测试过的所有设备上都能正常工作。将其转换市场一段时间后,我看到有几个人报告了一个问题。 map View 不拼
我在谷歌地图中用标记绘制了路径。所以路径是静态的,但标记需要改变它们的位置。如何在不使用 mapview.clear() 的情况下删除所有标记,因为它也会从 map 上清除我的路径。 有什么解决办法吗
在使用 react-native-maps 的 native 应用程序中,我试图以编程方式显示 MapView.Callout特定的 MapView.Marker在许多之中。我打算使用 showCal
我将尝试在名为 RoeteFragment 的 fragment 上显示我的 Android 应用程序中的 map 。如果我调试我的代码,我会看到方法 onMapReady 从未被调用,因此 map
我正在使用 mapbox 和 firebase。我有一个委托(delegate)函数,当用户的位置发生变化时,它会更新用户的坐标(在 firebase 数据库内部)。据我所知,它在登录到应用程序后可以
我在 SwiftUI 中使用 GMSMapView,在 map View 中我必须显示一些带有经纬度的标记。单击任何标记后,我必须移动到另一个 View 。我这样做是通过将 MapView 放入 导航
我想找到一种简单的方法来获取路线。有没有办法用mapview来做到这一点?下面是我当前的代码。 - (IBAction)goToMap:(id)sender { [self.view addSubvi
我正在尝试为 map 创建自定义注释。我遇到的问题是,我无法使注释一个接一个地删除。所有销钉同时落下。这是 didAddAnnotations 的委托(delegate)代码。你能帮我重写代码,以便我
我正在制作一款 iPhone 应用程序,该应用程序专为密苏里州本地的事物而设计。所以我的想法是将 map 限制为仅密苏里州/靠近密苏里州的地区。我的 map 工作正常,显示用户的位置,如果他们更新位置
是否可以让嵌入的 MKMapView 旋转以始终面向 iPhone 所面向的方向?基本上我想在我自己的应用程序上模仿 map 应用程序旋转功能。 我发现 iPhone SDK 没有公开该功能。但是,我
我已加载用户当前位置的自定义注释图像。我将在后台每 1 秒更新一次当前用户位置。 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
我是一名优秀的程序员,十分优秀!