我想在地图的左侧显示我当前的位置。
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = 26.926;
theCoordinate.longitude = 75.8235;
MKCoordinateRegion region;
region.center = theCoordinate;
MKCoordinateSpan span;
span.latitudeDelta = 0.005;
span.longitudeDelta = 0.005;
region.span=span;
[mapView setRegion:region animated:TRUE];
上面的代码显示了我在地图中心的位置,因为这行:
region.center = theCoordinate;
有没有办法在除中心以外的任何特定位置更改此内容?
谢谢。
Nitesh
答案 0 :(得分:0)
这不是Objective-C特有的。如果所需位置位于地图左侧,则需要计算中心的位置。也就是说,给定一个宽度为X的像素图和比例尺T,我位置以东的X / 2像素点的长/纬度是多少。完成后,您可以指定
region.center = theNewCoordinate;
答案 1 :(得分:0)
你可以添加一种偏移吗?
CLLocationCoordinate2D coordinatesForCenter = [theCoordinate copy];
// Add an offset :
coordinatesForCenter.latitude+=5; // 5 for exemple (it's not significant)
coordinatesForCenter.longitude+=5;
// Center on your new coordinates :
region.center = coordinatesForCenter;
希望它有所帮助。