0

我需要一个很好的教程,在该教程中,用户的当前位置(纬度、经度、城市、州、国家)随着位置的变化而不时更新并显示在地图工具包上,蓝色图标缩放。

我通过在 view.xib 上放置一个 MKMapView 来做到这一点,它仅第一次显示用户的当前位置(模拟器上的默认设置:SanFransisco),蓝点缩放。但是当我下次运行该应用程序时,它没有显示任何蓝点缩放。我应该写任何代码吗?直到现在我还没有写任何代码。刚刚在 xib 中放置了一个带有 Show UserLocation 的 mapkit。我怎样才能得到一个蓝点?

我还需要从用户位置找到附近的医生,并用红色标记指向同一张地图。

通过谷歌但很困惑。请在这方面向我推荐一些好的教程。

编辑:

- (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];
    });
}

//这里我将数组数据设为空,因为纬度和经度作为 0.000 传递。

如何在 viewDidLoad 上同时获取它们?

4

2 回答 2

0

如果您想找到附近的医生地址,您需要使用“GOOGLE PLACE API”

//获取用户当前位置

CLLocationCoordinate2D location = [[[mapview userLocation] location] 坐标];
NSLog(@"从地图中找到的位置:%f %f",location.latitude,location.longitude);

检查此链接它是google place api的好例子

于 2012-12-03T06:48:59.607 回答
0

Add this Delegate method of ccl location manager

.h file

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];
    });
}

pass the current latitude and longitude in your -(void) queryGooglePlaces: (NSString *) googleType { } method

于 2012-12-03T11:44:12.183 回答