编辑:这不一定是参考模拟器,使用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