【问题标题】:any method to show user location in ios在 ios 中显示用户位置的任何方法
【发布时间】:2014-04-16 04:12:32
【问题描述】:
是否有任何方法以纬度和经度作为参数和谷歌地图链接或苹果地图链接这三个参数来在谷歌地图或苹果地图上显示用户位置,以便用户可以使用谷歌创建的谷歌地图功能,如箭头方向或放大/out。
我不想使用 iOS 的 MKMapView 在我的应用中显示用户位置。
提前谢谢给我任何很酷的方法(纬度,经度,谷歌地图链接)作为参数。
【问题讨论】:
标签:
objective-c
ios7
xcode5
【解决方案1】:
仅对于坐标,您需要 CoreLocation,所以请 google。
但如果您需要显示地图和箭头,则确实需要地图框架。要么选择内置的 MKMapKit,也可以下载 Google Maps SDK。
【解决方案2】:
首先,请导入这个框架
#import
,要导入这个框架,你需要选择你的项目然后去构建阶段,点击link binaries with library并添加core location framework。
在 view didload 方法中在您的视图控制器中添加此代码:-
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest; // 100 m
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[locationManager requestAlwaysAuthorization];
}
[locationManager startUpdatingLocation];
// Mapview 的代表
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 800, 800);
[map_View setRegion:[map_View regionThatFits:region] animated:YES];
if (newLocation != nil) {
NSLog(@"%f %f",currentLocation.coordinate.longitude,currentLocation.coordinate.latitude);
[locationManager stopUpdatingLocation];
locationManager = nil;
}
// Reverse Geocoding
CLGeocoder *geocoder = [CLGeocoder new];
dispatch_async(dispatch_get_main_queue(), ^{
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
} else {
NSLog(@"%@", error.debugDescription);
}
} ];
});
}
不要忘记在您的 plist 文件中添加这一行:-
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription