Редактировать: Это не обязательно относится к симулятору, в котором используется объект Debug-> Location. Он показывает 0.000000 ли я на симуляторе или на реальном телефоне.Карты Google Maps SDK на iOS (не Simulator!), MyLocation - 0.000000
Я использую карты Google, чтобы попытаться создать приложение, которое может делать что-то на основе моего текущего местоположения.
Когда я открываю приложение, точка синей точки на карте находится в моем фактическом (правильном) месте, но маркер, который я разместил в «myLocation», составляет 0,000000,0.000000 (это также значение, которое печатается на консоль)
Как я могу сделать так, чтобы местоположение моего маркера находилось в текущем местоположении, когда я открываю приложение и/или что-то делаю, чтобы получить живые координаты, где находится синяя точка? (Таким образом, я мог бы получить доступ к широте и долготе в реальном времени, когда захочу)
Заранее спасибо!
Вот мой код:
#import "MyViewController.h"
#import <GoogleMaps/GoogleMaps.h>
@interface MyViewController()
@property (nonatomic, readwrite) NSString *coord;
@end
@implementation MyViewController
GMSMapView *mapView_;
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view layoutIfNeeded];
// Do any additional setup after loading the view, typically from a nib.
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
CLLocation *myLocation = mapView_.myLocation;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:myLocation.coordinate.latitude
longitude:myLocation.coordinate.longitude
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
// marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.position = CLLocationCoordinate2DMake(myLocation.coordinate.latitude, myLocation.coordinate.longitude);
marker.title = @"Current:";
float lat = mapView_.myLocation.coordinate.latitude;
float lon = mapView_.myLocation.coordinate.longitude;
_coord = [NSString stringWithFormat:@"%f %f",lat,lon];
printf("%f %f",lat,lon);
marker.snippet = (_coord);
marker.map = mapView_;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Возможный дубликат [Можно ли получить текущее местоположение в реальном времени с помощью симулятора iOS?] (Http://stackoverflow.com/questions/21102917/is-it-possible-to-get-the-live -current-location-with-an-ios-simulator) –
Я не говорю об Simulator, я говорю о том, чтобы получить текущее местоположение из API Карт Google на реальном iPhone. – Inbl