[英]User current Location on a mapkit in xcode
我需要一个很好的教程,其中会随着位置的变化而不断发现并更新用户的当前位置(纬度,经度,城市,州,国家/地区),并以蓝色图标缩放的方式显示在地图工具包上。
我是通过在view.xib上放置一个MKMapView来做到这一点的,它显示了用户的当前位置(模拟器上的默认设置:SanFransisco),并且只有第一次才具有蓝点缩放功能。 但是,当我下次运行该应用程序时,它没有显示任何蓝点缩放。 我应该写任何代码吗? 到目前为止,我还没有编写任何代码。 刚刚放置了一个xkit,并在xib中选中了Show UserLocation。 如何获得蓝点?
我还需要从用户位置中找到附近的医生,并在同一张地图上显示带有红色标记的位置。
通过谷歌去了,但很困惑。 请向我建议一些有关这方面的好教程。
编辑:
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[self.mapView setShowsUserLocation:YES];
[locationManager startUpdatingLocation];
[self queryGooglePlaces:@"doctor"];
}
-(void) queryGooglePlaces: (NSString *) googleType {
// https://developers.google.com/maps/documentation/places/#Authentication
NSString *url = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=300&types=doctor&sensor=true&key=%@", coord.latitude, coord.longitude,kGOOGLE_API_KEY];
NSURL *googleRequestURL=[NSURL URLWithString:url];
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
//这里我将数组数据设置为null,因为纬度和经度以0.000传递。
如何在viewDidLoad上同时获取它们?
如果要查找附近的医生地址,则需要使用“ GOOGLE PLACE API”
//用于用户当前位置
CLLocationCoordinate2D location = [[[[mapview userLocation] location]坐标];
NSLog(@“从地图找到位置:%f%f”,location.latitude,location.longitude);
添加ccl位置管理器的此Delegate方法
.h文件
double currentLatitude;
double currentLongitude;
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
currentLatitude = newLocation.coordinate.latitude;
currentLongitude = newLocation.coordinate.longitude;
[self queryGooglePlaces:somestring];
}
-(void) queryGooglePlaces: (NSString *) googleType {
// https://developers.google.com/maps/documentation/places/#Authentication
NSString *url = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=300&types=doctor&sensor=true&key=%@", currentLatitude , currentLongitude,kGOOGLE_API_KEY];
NSURL *googleRequestURL=[NSURL URLWithString:url];
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
在-(void) queryGooglePlaces: (NSString *) googleType { }
传递当前的纬度和经度-(void) queryGooglePlaces: (NSString *) googleType { }
方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.