2013-05-11 2 views

ответ

3

Вы можете получить координаты точки в центре карты со свойствами MKMapView: centerCoordinate.latitude и centerCoordinate.longitude.

Например:

CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(
       map.centerCoordinate.latitude, map.centerCoordinate.longitude); 

Вот тезисы широта и долгота вы имеете в виду «я нужна широта и долгота, когда пользователь перемещает карту»?

Надеется, что это помогает ...

+0

Как мы можем узнать, что пользователь перемещает карту. – user1969021

+1

Я никогда не пробовал этого, но относится к [Apple Documentation] (http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html), '- (void) mapView: (MKMapView *) mapView regionDidChangeAnimated: (BOOL) анимированный', кажется, хороший метод делегата. – Lucien

1

Используйте .region свойство ваш MKMapView.

MKMapView *myMapView = [[MKMapView alloc] initWithFrame:...]; 

MKCoordinateRegion region = myMapView.region; 

// Center of the screen as lat/long 
// region.center.latitude 
// region.center.longitude 

// width and height of viewing area as lat/long 
// region.span.latitudeDelta 
// region.span.longitudeDelta 

Max

+0

я нужна широта и долгота, когда пользователь перемещает карту с finger.and каждый раз, когда я пошлю эту широчайшую и долготу, чтобы найти рестораны. – user1969021

+0

Привет mxweas У меня есть одно сомнение – user1969021

1

Добавить это в Appdelegate.h

CLLocationManager *locationManager; 

, а затем добавить эти строки в ваш Appdelegate.m (didFinishLaunchingWithOptions)

locationManager = [[CLLocationManager alloc] init]; 
locationManager.delegate = self; 
locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
[locationManager startMonitoringSignificantLocationChanges]; 
[locationManager startUpdatingLocation]; 

это будет вызывать метод при перемещении с устройством,

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{ 
    CLLocation *currentLocation = [locations lastObject]; 

    NSString *latitude = [NSString stringWithFormat:@"%g", currentLocation.coordinate.latitude]; 
    NSString *longitude = [NSString stringWithFormat:@"%g", currentLocation.coordinate.longitude]; 

    NSMutableArray *temp = [[NSMutableArray alloc] initWithCapacity:0]; 
    [temp addObject:latitude]; 
    [temp addObject:longitude]; 

    NSUserDefaults *def = [NSUserDefaults standardUserDefaults]; 
    [def setObject:temp forKey:@"CLocation"]; 

    [temp release]; 
} 

Используйте это.

+0

его штраф, но мне нужна широта и долгота, когда пользователь перемещает карту пальцем. – user1969021

+0

Привет, sathia moorthy – user1969021