Google iOS sdk maps get overlay overlay coordinates

I work with Google maps iOS sdk. I want to get the coordinates of the affected point when the user removes the overlay.

this delegation method exists:

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate

but it is not called when you click the overlay or marker.

Can I call it programmatically (but there is no coordinate parameter - what do I want ..)? or get location from this:

- (void) mapView: (GMSMapView *) mapView  didTapOverlay: (GMSOverlay *) overlay

any offer is precious!

thank!

+4
source share
6 answers

UPDATE 6/2/15

UITapGestureRecognizer , . didTapAtCoordinate didTapAtOverlay .

  UITapGestureRecognizer *touchTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouchTap:)];
  [self.view addGestureRecognizer:touchTap];

-(void)tapTouchTap:(UITapGestureRecognizer*)touchGesture
{
  CGPoint point = [touchGesture locationInView:self.view];
  CLLocationCoordinate2D coord = [self.mapView.projection coordinateForPoint:point];
  NSLog(@"%f %f", coord.latitude, coord.longitude);
}

, . GMSMapViewDelegate :

@interface Map : UIViewController <GMSMapViewDelegate>

viewDidLoad:

self.mapView.delegate = self;

:

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

, position

CLLocationCoordinate2D coord = marker.position;

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate

, .

GMSOverlay , GMSMarker. GMSOverlay position. , , didTapAtCoordinate, ( GPS) .

+2

self.mapview.settings.consumesGesturesInView = NO;

viewdidload .

.

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
    NSLog(@"%g",coordinate);
}


- (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay
{

    GMSCircle *circle=(GMSCircle *)overlay;
    CLLocationCoordinate2D touchCoOrdinate= circle.position;
    NSLog(@"%g",touchCoOrdinate);
}
+1

, didTapAtCoordinateMethod . .

, , . .

    //draw line
    GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
    polyline.strokeColor = [UIColor purpleColor];
    polyline.tappable = TRUE;
    polyline.map = self.googleMapView;
    polyline.title = routestring;

-

routestring = [NSString stringWithFormat:@"%@/%@/%@",lat,lng,[annnotationobject objectForKey:@"linkId"]];

lat lng . .

Routestring , '/', , . .

, :

-(void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay{

NSString *path = overlay.title;

//Finding componentpaths of string
NSArray *pathparts = [path pathComponents];
NSString *lat = [pathparts objectAtIndex:0];
NSString *lng = [pathparts objectAtIndex:1];
NSString *linkID = [pathparts objectAtIndex:2];

//Here we are building a marker to place near the users tap location on the polyline.
GMSMarker *marker = [GMSMarker markerWithPosition:CLLocationCoordinate2DMake([lat doubleValue],[lng doubleValue])];
marker.title = overlay.title;
marker.snippet = @"ROUTE DATA";
marker.map = self.googleMapView;

//This will popup a marker window
[self.googleMapView setSelectedMarker:marker];

}

, ( "/" ), . .

0

tappable ( ) didTapAtCoordinate.

, , , , .

0

UITapGestureRecognizer touchesEnded, , GMSMapView.

UITapGestureRecognizer mapView:

self.touchTap = [[TouchGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouchTap)];
self.touchTap.mapView = self.mapView;
[self.view addGestureRecognizer:self.touchTap];

TouchDownGestureRecognizer.h:

#import <UIKit/UIKit.h>    

@interface TouchGestureRecognizer : UITapGestureRecognizer
@property  GMSMapView       *mapView;
@end

TouchDownGestureRecognizer.m:

#import "TouchGestureRecognizer.h"
#import <UIKit/UIGestureRecognizerSubclass.h>

@implementation TouchGestureRecognizer

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
  [super touchesEnded:touches withEvent:event];

  UITouch *touch = touches.allObjects[0];
  CGPoint point = [touch locationInView:self.mapView];
  CLLocationCoordinate2D coord = [self.mapView.projection coordinateForPoint:point];
  NSLog(@"%f %f", coord.latitude, coord.longitude);
}

@end
0

Source: https://habr.com/ru/post/1541955/


All Articles