2013-05-11 61 views

回答

3

您可以使用MKMapView的屬性獲取地圖中心點的座標: centerCoordinate.latitudecenterCoordinate.longitude

例如:

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

這是論文緯度和你所說的「當用戶移動地圖我需要的經度和緯度」是指東經?

希望這有助於...

+0

我們如何才能找出用戶有移動地圖。 – user1969021 2013-05-11 13:13:38

+1

我從來沒有嘗試過,但關於[Apple文檔](http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html),' - (void) mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated'似乎是很好的委託方法。 – Lucien 2013-05-11 17:33:50

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 

最大

+0

我需要的緯度和經度,當用戶移動地圖finger.and每次我都會發送這個緯度和經度找到餐館。 – user1969021 2013-05-11 07:18:55

+0

嗨mxweas我有一個懷疑 – user1969021 2013-06-18 05:53:45

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 2013-05-11 07:11:13

+0

嗨sathia moorthy – user1969021 2013-06-18 05:52:41

相關問題