iphone – 使用MKCoordinateRegion在NSString纬度和经度坐标上聚焦MKMapView

iphone – 使用MKCoordinateRegion在NSString纬度和经度坐标上聚焦MKMapView,第1张

概述我有一个纬度经度坐标,我想集中我的地图.它们存储为NSStrings并转换为以下位置: NSString *placeLatitude = [elementCoords objectForKey:@"placeLatitude"];NSString *placeLongitude = [elementCoords objectForKey:@"placeLongitude"];CLLoca 我有一个纬度和经度坐标,我想集中我的地图.它们存储为Nsstrings并转换为以下位置:

Nsstring *placeLatitude = [elementCoords objectForKey:@"placeLatitude"];Nsstring *placeLongitude = [elementCoords objectForKey:@"placeLongitude"];CLLocationCoordinate2D location;location.latitude = [placeLatitude doubleValue];location.longitude = [placeLongitude doubleValue];

我如何修改以下内容以不关注用户的当前位置,而是关注上面指定的纬度和经度?

MKCoordinateRegion mapRegion;mapRegion.center = mapVIEw.userLocation.coordinate;mapRegion.span.latitudeDelta = 0.05;mapRegion.span.longitudeDelta = 0.05;
解决方法 我会使用 setCenterCoordinate:animated:来移动地图焦点.如果您正在加载视图并希望立即将其设置到正确的位置,请设置动画:否,否则,如果要平移地图以平滑居中位置,则设置动画:是

[mapVIEw setCenterCoordinate:location animated:YES];

当然,这不会改变地图视图的缩放级别.如果要更新缩放级别,则应使用setRegion:animated:.例如,如果要放大两倍:

// Halve the wIDth and height in the zoom level.// If you want a constant zoom level,just set .longitude/latitudeDelta to the// constant amount you would like.// Note: a constant longitude/latitude != constant distance depending on distance//       from poles or equator.MKCoordinateSpan span =    { .longitudeDelta = mapVIEw.region.span.longitudeDelta / 2,.latitudeDelta  = mapVIEw.region.span.latitudeDelta  / 2 };// Create a new MKMapRegion with the new span,using the center we want.MKCoordinateRegion region = { .center = location,.span = span };[mapVIEw setRegion:region animated:YES];
总结

以上是内存溢出为你收集整理的iphone – 使用MKCoordinateRegion在NSString纬度和经度坐标上聚焦MKMapView全部内容,希望文章能够帮你解决iphone – 使用MKCoordinateRegion在NSString纬度和经度坐标上聚焦MKMapView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1058362.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存