I am facing a problem from last 2 days. I am working on a Google map App using Google Map API. I get user's current location and drop a pin also. but my requirement is when user tap on any position of map i need that touch location latitude & longitude value.
How can i get it. Please don't say below code.
CGPoint touchPoint = [gestureRecognizer locationInView:mapView_];
coordinate = [mapView_ convertPoint:touchPoint toCoordinateFromView:mapView_];
This code is working for MKMapView not for Google map API.
And another issue is i am unable to touch the mapview also. I share my code below. Please someone help me.
This is my .h File
#import <UIKit/UIKit.h>
#import <GoogleMaps/GoogleMaps.h>
#import <MapKit/MapKit.h>
@interface ViewController : UIViewController <MKMapViewDelegate>
{
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
This is my .m File
@implementation ViewController
{
GMSMapView *mapView_;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
float latitude = self.locationManager.location.coordinate.latitude;
float longitude = self.locationManager.location.coordinate.longitude;
NSLog(@"*dLatitude : %f", latitude);
NSLog(@"*dLongitude : %f",longitude);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude longitude:longitude zoom:8];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.settings.myLocationButton = YES;
self.view = mapView_;
// Creates a marker in the center of the map.
GMSMarker *pinview = [[GMSMarker alloc] init];
pinview.position = CLLocationCoordinate2DMake(latitude, longitude);
//pinview.icon = [UIImage imageNamed:@"pin"];
pinview.icon = [GMSMarker markerImageWithColor:[UIColor blueColor]];
pinview.title = @"Bangalore";
pinview.snippet = @"IntegraMicro";
pinview.map = mapView_;
UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc]initWithTarget:self
action:@selector(handleGesture:)];
tgr.numberOfTapsRequired = 1;
[mapView_ addGestureRecognizer:tgr];
}
How to get touch location latitude and longitude value and how to add tap gesture on mapview.
Please help me.
Thanks :)