固定在Google Maps iOS SDK中心的标记 [英] fixed marker on center of google map ios sdk
问题描述
我想将标记固定在地图中心,而不管位置坐标如何.如果用户在地图上移动相机,我希望它一直显示在中心,而标记上没有任何闪烁,并且显示了该标记上的新位置,请问该怎么办?请帮忙.谢谢
I want to fix the marker in the center of the map irrespective of the location coordinates. If the user moves the camera on map I want it to keep showing up in the center without any flickering in marker and new location on that marker shows,If it is possible then How can I do that? Please help out. Thanks
我正在使用iOS google map sdk(objective-c)
i am using iOS google map sdk(objective-c)
推荐答案
GMSCameraPosition *lastCameraPosition;
- (void)mapView:(GMSMapView *)pMapView didChangeCameraPosition:(GMSCameraPosition *)position {
/* move draggable pin */
if (movingMarker) {
// stick it on map and start dragging from there..
if (lastCameraPosition == nil) lastCameraPosition = position;
// Algebra :) substract coordinates with the difference of camera changes
double lat = position.target.latitude - lastCameraPosition.target.latitude;
double lng = position.target.longitude - lastCameraPosition.target.longitude;
lastCameraPosition = position;
CLLocationCoordinate2D newCoords = CLLocationCoordinate2DMake(movingMarker.googleMarker.position.latitude+lat,
movingMarker.googleMarker.position.longitude+lng);
[movingMarker.googleMarker setPosition:newCoords];
return;
}
}
- (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position {
lastCameraPosition = nil; // reset pin moving, no ice skating pins ;)
}
现在,上面的代码使标记保持原样,但是在拖动屏幕时它正在飞行.
now the code above makes the marker stay as it was but it's flying while you drag the screen.
如果要使其首先居中,则必须将标记坐标设置为map.center->坐标转换,然后要做一些动画:
if you want it centered first the you have to set the marker coordinates to map.center -> coordinates conversion and then you have some animation to do:
CGPoint point = map.center; GMSCameraUpdate *camera =[GMSCameraUpdate setTarget:[map.projection coordinateForPoint:point]];
[map animateWithCameraUpdate:camera];
然后等待map:mapDidIdle
then wait for map:mapDidIdle
这篇关于固定在Google Maps iOS SDK中心的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!