我需要在Google地图上选择当前标记位置的坐标。当标记在地图上移动时,它应该更新坐标。
我正在使用 GoogleMaps , GooglePlaces 和 GooglePlacePicker API。我可以使用 GooglePlacePicker API来附近的地方,但我想选择存在标记的位置的精确坐标。
已经在优步中完成了?
答案 0 :(得分:0)
使用此,
·H
@interface ViewController : UIViewController <CLLocationManagerDelegate> {
GMSMapView *mapView_;
GMSMarker *marker_;
float currentLatitude;
float currentLongitude;
}
@property(nonatomic,retain) CLLocationManager *locationManager;
@property (nonatomic)CLLocationCoordinate2D coordinate;
的.m
- (void)viewDidLoad {
[super viewDidLoad];
_locationManager = [[CLLocationManager alloc] init];
[_locationManager setDelegate:self];
[_locationManager setDistanceFilter:kCLDistanceFilterNone];
[_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
if (IS_OS_8_OR_LATER) {
if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[_locationManager requestWhenInUseAuthorization];
}
}
[_locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog(@"%@",locations);
CLLocation *currentLoc=[locations objectAtIndex:0];
NSLog(@"CurrentLoc : %@",currentLoc);
_coordinate=currentLoc.coordinate;
currentLatitude = currentLoc.coordinate.latitude;
currentLongitude = currentLoc.coordinate.longitude;
}
-(void)plotMarkerForLatitude:(float)latitude andLongitude:(float)longitude {
// Now create maker on current location
if (marker_ == NULL) {
marker_ = [[GMSMarker alloc] init];
}
CLLocationCoordinate2D target =
CLLocationCoordinate2DMake(latitude, longitude);
marker_.position = target;
marker_.title = @"title";
marker_.appearAnimation = kGMSMarkerAnimationPop;
NSLog(@"%f %f",latitude,longitude);
marker_.icon = [UIImage imageNamed:@"marker"];
marker_.snippet = @"Address";
marker_.map = mapView_;
}
在Plist中:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Allow access to get your current location</string>
答案 1 :(得分:0)
这可以通过实施GMSMapViewDelegate协议来完成。请参阅GMSMapViewDelegate
上的guide to events和方法列表。
如文档中所述,
应用程序可以使用此事件触发刷新GMSMapView上显示的标记或其他内容,而不是例如在每次更改相机时重新加载内容。
您还可以查看Google Maps SDK for iOS,了解有关可以与Maps iOS SDK一起使用的其他API的更多信息,以构建与位置相关的应用和网站。