简体   繁体   English

Google Maps iOS-点击标记以显示默认的Google路线按钮

[英]Google Maps iOS - Tapping on Marker to show default google directions button

In Android on tapping on a marker two buttons show on the screen at the bottom for direction and opening google maps. 在Android中,点击标记时,屏幕底部会显示两个按钮,用于指示方向和打开Goog​​le地图。 However, on iOS tapping marker only shows info window. 但是,在iOS上,点击标记仅显示信息窗口。

I need to show the info window and directions and google maps buttons on tapping marker just as in Android. 我需要像在Android中一样在点击标记时显示信息窗口和方向以及Google地图按钮。

My code for adding markers: 我添加标记的代码:

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = [(CLLocation*)dict[@"position"] coordinate];
marker.icon = [GMSMarker markerImageWithColor:[UIColor ubnBlue]];
marker.title = dict[@"title"];
marker.snippet = dict[@"snippet"];
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.tappable = YES;
marker.map = mapView_;

First set GMSMapViewDelegate method 首先设置GMSMapViewDelegate方法

- (BOOL) mapView: (GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
{
    [mapView setSelectedMarker:marker];
    return YES;
}

- (UIView *GMS_NULLABLE_PTR)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
   NSLog(@"The amrker snippet is - %@",marker.snippet);
   if([marker.snippet isEqualToString:@"your string"]) //check here
   {
       ....//Do the stuff here
   }
}

First, you need to set the delegate method in yourController.h file then you can handle it by using the method 首先,您需要在yourController.h文件中设置委托方法,然后可以使用该方法来处理它

- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {

return Yes;

}

to show the info window you need to call a marker.title = @"title"; 要显示信息窗口,您需要调用marker.title = @"title";

GMSMarker has property iconView. GMSMarker具有属性iconView。 You can assign UIView to iconView. 您可以将UIView分配给iconView。

Implement GMSMapViewDelegate delegate methods 实现GMSMapViewDelegate委托方法

(BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {

}

Now you can change your view as you need. 现在,您可以根据需要更改视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM