2016-04-07 2 views
0

Ich bekomme die aktuelle Einstellung und Längengrad des Geräts und drucke es mit NSLog, aber jetzt wie diese Lattitude und Longitude auf der Karte entsprechend aktualisiert werden. Hier ist mein Code, bitte sieh dir das an.Wie bekomme ich den aktuellen Standort in iOS mit Google Map API?

- (void)viewDidLoad { 
[super viewDidLoad]; 



GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868 
                 longitude:151.2086 
                  zoom:12]; 

mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 



mapView_.settings.myLocationButton = YES; 
self.view = mapView_; 
mapView_.settings.compassButton = YES; 

[self startStandardUpdates]; 

    } 



      - (void)startStandardUpdates 
     { 
// Create the location manager if this object does not 
// already have one. 

NSLog(@"startupdatelocation"); 
if (nil == _locationManager) 
    _locationManager = [[CLLocationManager alloc] init]; 

_locationManager.delegate = self; 
_locationManager.desiredAccuracy = kCLLocationAccuracyKilometer; 

// Set a movement threshold for new events. 
_locationManager.distanceFilter = 10; // meters 

[self.locationManager startUpdatingLocation]; 
     } 



     - (void)startSignificantChangeUpdates 
     { 
// Create the location manager if this object does not 
// already have one. 
if (nil == _locationManager) 
    _locationManager = [[CLLocationManager alloc] init]; 

_locationManager.delegate = self; 
[self.locationManager startMonitoringSignificantLocationChanges]; 
     } 

     - (void)locationManager:(CLLocationManager *)manager 
didUpdateLocations:(NSArray *)locations { 
// If it's a relatively recent event, turn off updates to save power. 
CLLocation* location = [locations lastObject]; 
NSLog(@"location %@", location); 
NSDate* eventDate = location.timestamp; 
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; 
if (abs(howRecent) < 15.0) { 
    // If the event is recent, do something with it. 
    NSLog(@"latitude %+.6f, longitude %+.6f\n",location.coordinate.latitude, 
      location.coordinate.longitude); 



     } 
     } 

Ich drucke aktuelle Breiten- und Längengrad jetzt, wie werde ich diesen Ort auf der Karte zeigen, in dieser Situation bittet mir auch helfen.

+0

der Grund, warum Sie die statischen Koordinaten hinzugefügt ** cameraWithLatitude: -33,868 Longitude: 151.2086 ** –

+0

ok sir aber wenn ich diese Zeile Code entfernen, wird nichts angezeigt –

+0

Ich importiere bereits Corelocation-Framework, aber es funktioniert nicht –

Antwort

0

Aktuelle Gerätestandort sollte aus dem iOS angefordert werden - https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html

als Sie die Markierung mit Geräten Standort auf der Karte

zeigen konnten
+0

sollte ich Schlüsselwert in Plist für diese "UIRequiredDeviceCapabilities" hinzufügen? –

+0

@sandeeptomar NSLocationWhenInUseUsageDescription und NSLocationAlwaysUsageDescription werden Schlüssel benötigt. Lesen Sie mehr hier zum Beispiel http://stackoverflow.com/questions/26134641/how-to-get-current-location-lat-long-in-ios-8 –

Verwandte Themen