簡體   English   中英

居中自定義標記GMSMapView

[英]Centering custom marker GMSMapView

我正在嘗試使用Google Maps在iOS(Objective-C)中定位自定義標記。

使用標記可以很好地顯示地圖視圖,但是,移動地圖會將標記與標記一起作為其當前位置。 我正在尋找的是將其設置為地圖容器的中心,然后它將獲取地圖圖釘的坐標並顯示在搜索欄中。

我以為我是在反向執行此操作? 我將客戶標記添加為地圖容器的UIImage,但是它仍然不顯示。 我應該從地圖標記的位置獲取位置,然后從那里反向對地址進行地理編碼。

- (void)addPins:(float)lat andLng:(float)lng andName:(NSString*)strName withAddress:(NSString*)strAddr
{
    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(currentUserLocation.coordinate.latitude, currentUserLocation.coordinate.longitude);

    NSLog(@"lat : %f, lng : %f", lat, lng);

    marker.icon = [UIImage imageNamed:@"map_pin"];
    marker.title = strName;
    marker.snippet = strAddr;
    marker.appearAnimation = kGMSMarkerAnimationPop;
    marker.map = mapView;
}

除了當前位置之外,用戶還需要能夠搜索和設置其地址。

謝謝

使用您的mapView委托並使用響應程序來重新定位圖釘並重新觸發地理坐標查找。

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

編輯:如果GMS Maps沒有這些委托,則該方法可以使用它們記錄的任何[mapView didUpdate]回調都可以使用。

您可以設置GMSCameraPosition以使標記居中

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:"YOUR LATITUDE"
                                                                longitude:"YOUR LONGITUDE"
                                                                     zoom:centerZoom];

"YOUT GMSMAPVIEW" = [GMSMapView mapWithFrame:"YOUR VIEW".bounds camera:camera];

暫無
暫無

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

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