簡體   English   中英

Xcode中Mapkit上的用戶當前位置

[英]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);

檢查此鏈接是Google Place API的好例子

添加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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM