簡體   English   中英

Google Maps SDK iOS - 防止地圖在縮放時更改位置

[英]Google Maps SDK iOS - prevent map from changing location on zoom

我有一個問題,我有一段時間無法解決。

我在它的前面有一個帶有imageView的GMSMapView。 結果 - 我可以拖動地圖並始終有中心針。 但是當我縮放地圖時會出現問題。 在縮放 - 地圖目標更改的位置和我的imageView指向另一個位置。

我可以檢測到縮放是否發生變化,但實際上我無法強制GMSMapView進行縮放而不會改變任何位置。

-(void) mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position
{
    if (mZoomLevel != mapView.camera.zoom)
    {
        mZoomLevel = mapView.camera.zoom;
    }
}

所以基本上,即使我執行縮放,我也希望始終有中心針。 我嘗試過GMSMarker - 但是在關注地圖中心時遇到了性能問題。 它沒有立即執行,所以我決定使用imageView。

主要問題:如何在執行縮放時鎖定地圖的當前位置?

Google用谷歌地圖sdk 1.10.0解決了這個問題。

解決方案是在配置GMSMapview時簡單地添加此行:

_mapView.settings.allowScrollGesturesDuringRotateOrZoom = NO;

好吧,經過10天回到這個問題,我終於解決了! 答案很簡單!

這里幾步:1。在GMSMapView上添加imageView作為標記2.將UIPanGestureRecognizer添加到GMSMapView(不要忘記設置委托,這很重要)3。然后使用此代碼:

- (void) didPan:(UIPanGestureRecognizer*) gestureRecognizer
{
    if (gestureRecognizer.state == UIGestureRecognizerStateEnded)
    {
        _mapView.settings.scrollGestures = true;
    }
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    if (gestureRecognizer.numberOfTouches > 1)
    {
        _mapView.settings.scrollGestures = false;
    }
    else
    {
        _mapView.settings.scrollGestures = true;
    }
    return true;
}

斯威夫特3:

mapView.settings.scrollGestures = false

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM