我想修復標記在地圖的中心,無論位置座標。如果用戶在地圖上移動相機,我希望它在中間不會出現任何閃爍的標記,並且該標記上的新位置會顯示,我該怎麼做?請幫忙。Objectivec固定標記谷歌地圖中心ios
4
A
回答
2
試試下面的代碼
GMSCameraPosition *cameraPosition;
- (void)mapView:(GMSMapView *)pMapView didChangeCameraPosition:(GMSCameraPosition *)position {
/* move draggable pin */
if (fixedMarker) {
// 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(fixedMarker.googleMarker.position.latitude+lat,
fixedMarker.googleMarker.position.longitude+lng);
[fixedMarker.googleMarker setPosition:newCoords];
return;
}
}
- (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position {
cameraPosition = nil; // reset pin moving, no ice skating pins ;)
}
+1
嗨Basir,它工作正常,但如果我移動地圖,標記也移動並固定在中心。但我希望它能繼續在中心顯示出來,而不會有任何閃爍的痕跡。 – Karthick
1
爲了不移動標記
創建的ImageView或按鈕(如果可點擊)的基礎上GMSMapView中的框架上的GMSMapView中的中心。
,如果你想要得到的座標,您可以使用mapView.projection.coordinateForPoint
這將通過下面的代碼
let centerCord = yourMapView.camera.target
let marker = GMSMarker(position: centerCord)
marker.title = "Hello World"
marker.map = mapView
實現MapView的移動谷歌地圖的標記
尋找中心點:didChangeCameraPosition:
func mapView(mapView: GMSMapView, didChangeCameraPosition position: GMSCameraPosition) {
// to remove all markers
mapView.clear()
//create new marker with new center
let centerCord = [yourMapView.camera target]
let marker = GMSMarker(position: centerCord)
marker.title = "Hello World"
marker.map = mapView
}
2
嘗試以下目標C代碼
不要忘記設置Delagate
mapView.delegate=self;
創建的ImageView並將其添加到中心地圖
UIImageView *pin =[[UIImageView alloc]init];
pin.frame=CGRectMake(0, 0, 20, 20 );
pin.center = mapView.center;
pin.image = [UIImage imageNamed:@"location.png"];
[self.view addSubview:pin];
[self.view bringSubviewToFront:pin];
然後用委託方法谷歌地圖
//When You Will Scroll Map Then This Method Will Be Called
- (void)mapView:(GMSMapView *)MapView didChangeCameraPosition:(GMSCameraPosition *)position {
// Get Latitude And Longitude Of Your Pin(ImageView)
CLLocationCoordinate2D newCoords = CLLocationCoordinate2DMake(position.target.latitude , position.target.longitude);
NSLog(@"Latitude-%f\Longitude-%f\n",newCoords.latitude, newCoords.longitude);
[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(newCoords.latitude, newCoords.longitude) completionHandler:^(GMSReverseGeocodeResponse* response, NSError* error) {
//Get Place Details
NSLog(@"%@",[[response results]objectAtIndex:0].lines);
}];
return;
}
相關問題
- 1. IOS谷歌地圖自定義標記
- 2. 谷歌地圖標記偏離中心
- 3. 從谷歌地圖中刪除固定標記
- 4. 谷歌地圖iOS標記不刪除
- 5. 谷歌地圖標記infowindow
- 6. android谷歌地圖標記
- 7. 谷歌地圖標記DROP
- 8. 谷歌地圖標記
- 9. 標記谷歌地圖
- 10. 谷歌地圖 - 多標記
- 11. 谷歌地圖標記
- 12. 標記在谷歌地圖
- 13. 谷歌地圖API標記
- 14. 谷歌地圖 - 多標記
- 15. 谷歌地圖:getSelected標記
- 16. RxJS谷歌地圖標記
- 17. 角谷歌地圖標記
- 18. 谷歌地圖標記
- 19. 在谷歌地圖中添加標記谷歌地圖反應
- 20. 谷歌地圖v3 - 設置界標到標記中心
- 21. 谷歌地圖V3自定義地圖標記圖標但是從谷歌
- 22. 自定義谷歌地圖標記
- 23. 谷歌地圖 - 定期更新標記
- 24. 谷歌地圖標記定義編號
- 25. 谷歌地圖API第3版:適合地圖標記,同時保持中心點固定
- 26. 如何在android中的谷歌地圖中心設置標記?
- 27. 保持谷歌地圖標記中心在所有視口中
- 28. 更改選定標記谷歌地圖iOS版
- 29. 在谷歌地圖上閃爍的自定義標記iOS
- 30. 谷歌地圖SDK iOS版:重新定位谷歌標誌
看到這個https://www.raywenderlich.com/109888/google-maps-ios-sdk-tutorial –