【发布时间】:2014-09-05 12:28:00
【问题描述】:
我在过去 2 天遇到了一个问题。我正在使用谷歌地图 API 开发谷歌地图应用程序。我得到用户的当前位置并放下一个别针。但我的要求是当用户点击地图的任何位置时,我需要触摸位置的纬度和经度值。
我怎样才能得到它。请不要说下面的代码。
CGPoint touchPoint = [gestureRecognizer locationInView:mapView_];
coordinate = [mapView_ convertPoint:touchPoint toCoordinateFromView:mapView_];
此代码适用于 MKMapView,不适用于 Google 地图 API。
另一个问题是我也无法触摸地图视图。我在下面分享我的代码。请有人帮助我。
这是我的 .h 文件
#import <UIKit/UIKit.h>
#import <GoogleMaps/GoogleMaps.h>
#import <MapKit/MapKit.h>
@interface ViewController : UIViewController <MKMapViewDelegate>
{
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
这是我的 .m 文件
@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];
}
如何获取触摸位置的纬度和经度值以及如何在地图视图上添加点击手势。
请帮帮我。
谢谢:)
【问题讨论】:
-
无法触摸地图视图是什么意思?您需要识别地图上的手势还是仅获取触摸位置?
-
我在该地图视图上添加了一个点击手势。但我无法触摸
标签: ios google-maps-api-3