1

私は自分のプロジェクトにmapkitフレームワークを統合しましたが、すべてが正常に機能します。私はこのようにユーザーの現在の位置を地図に表示するだけです:

mapView.delegate = self;
    mapView.showsUserLocation = YES;
    MKUserLocation *userLocation = mapView.userLocation;
    //numbers show map zoom. 500,500 = map stretches 500 meters to the North and the South of current location
    MKCoordinateRegion region =
    MKCoordinateRegionMakeWithDistance (userLocation.location.coordinate,1000,1000);
    [mapView setRegion:region animated:NO];

問題は、現在の位置の緯度と経度を2つの変数に保存する必要があることですが、これらの値はどこに保存されますか?

以下を印刷してみましたが、0.000になります。

NSLog(@"Latitude: %f" , mapView.userLocation.coordinate.latitude);
NSLog(@"Longitude: %f" , mapView.userLocation.coordinate.latitude);
4

4 に答える 4

3

このデリゲート メソッドを実装します。

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation

基本的に、MapView はユーザーの場所を特定すると、この場所を呼び出します。その場でuserLocationを確認しても、保証されません。

残りのデリゲート メソッドについては、MKMapViewDelegate プロトコル リファレンスを参照してください。

http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intf/MKMapViewDelegate

于 2012-06-26T14:47:17.523 に答える
2

これを使って:

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    NSLog(@"Latitude: %f" , userLocation.coordinate.latitude);
    NSLog(@"Longitude: %f" , userLocation.coordinate.latitude);
}
于 2012-06-26T14:54:26.590 に答える
0

もう 1 つの方法は、アドレスをテキストとして提供することです。

geocoder = [[CLGeocoder alloc] init];    

[geocoder geocodeAddressString:@"1 Infinite Loop" 
  completionHandler:^(NSArray* placemarks, NSError* error){
 for (CLPlacemark* aPlacemark in placemarks)
 {
     // Process the placemark.
 }
}];

ここで説明されています:https://developer.apple.com/library/ios/documentation/userexperience/conceptual/LocationAwarenessPG/UsingGeocoders/UsingGeocoders.html

于 2014-07-05T08:02:35.847 に答える
0
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    CLLocation *location = locations.lastObject;
    NSLog(@"Latitude: %f" , self.mapview.userLocation.coordinate.latitude);
    NSLog(@"Longitude: %f" , self.mapview.userLocation.coordinate.longitude);


}
于 2016-07-25T06:11:37.217 に答える