2016-08-07 3 views
0

Я пытаюсь создать информационное окно, такое же, как стандарт для маркеров, для отображения моей полилинии. Я получил NSLog для вывода, когда линия прослушивается, но теперь мне нужно, чтобы инфобокс отображался вместо NSLog. Я видел несколько примеров Javascript, но без объективных c.Пользовательская инфобокса при событии крана

- (void)loadView { 

// Create a GMSCameraPosition 
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:37.551927 
                 longitude:-77.456292 
                  zoom:18]; 
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(37.551709, -77.456510); 
mapView.settings.myLocationButton = YES; 
mapView.myLocationEnabled = YES; 
self.view = mapView; 
mapView.delegate = self; 

GMSMutablePath *path = [GMSMutablePath path]; 
[path addCoordinate:CLLocationCoordinate2DMake(37.552243, -77.457415)]; 
[path addCoordinate:CLLocationCoordinate2DMake(37.551054, -77.455443)]; 

GMSPolyline *polyline = [GMSPolyline polylineWithPath:path]; 

UILabel *myLabel = [[UILabel alloc] init]; 

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(labelTapped)]; 
tapGestureRecognizer.numberOfTapsRequired = 1; 
[myLabel addGestureRecognizer:tapGestureRecognizer]; 
myLabel.userInteractionEnabled = YES; 

polyline.spans = @[[GMSStyleSpan spanWithColor:[UIColor greenColor]]]; 
polyline.strokeWidth = 5.f; 
polyline.tappable = true; 
polyline.map = mapView; 

} 

- (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay 
{ 
    NSLog(@"in didTapOverlay"); 
} 

@end 

ответ

0

Проверите руководство Events из учебника по картам iOS. Вот фрагмент в Objective-C:

- (void)loadView { 
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285 
                  longitude:103.848 
                   zoom:12]; 
    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
    mapView.delegate = self; 
    self.view = mapView; 
} 

#pragma mark - GMSMapViewDelegate 

- (void)mapView:(GMSMapView *)mapView 
    didTapAtCoordinate:(CLLocationCoordinate2D)coordinate { 
    NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude); 
} 

Вот SO thread демонстрирует использование GMSMapViewDelegate:

1.conform к протоколу GMSMapViewDelegate.

@interface YourViewController() <GMSMapViewDelegate> 
// your properties 
@end 
2.set your mapView_ delegate. 

mapView_.delegate = self; 
3.implement the GMSMapViewDelegate method 

- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker { 
    // your code 
} 

Дополнение: marker.userData Полезно. вы можете установить в него необходимые данные и использовать его в - mapView:didTapInfoWindowOfMarker:

Смежные вопросы