編輯:這不一定是參考模擬器,使用Debug-> Location的東西。它顯示0.000000我是在模擬器上還是在真實的手機上。iOS上的Google Maps SDK(不是模擬器!),myLocation爲0.000000
我正在使用谷歌地圖試圖做一個應用程序,可以根據我當前的位置做事情。
當我打開應用程序時,地圖上的藍色點位置位於我的實際(正確)位置,但放置在「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 - 當前位置與一個IOS模擬器) –
我不是在談論模擬器,我說的是從真實iPhone上的Google Maps API獲取當前位置。 – Inbl