【发布时间】:2014-01-30 20:03:58
【问题描述】:
编辑:这不一定与模拟器有关,带有 Debug->Location 的东西。无论我是在模拟器上还是在真机上,它都会显示 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
【问题讨论】:
-
我说的不是模拟器,我说的是从真 iPhone 上的 Google Maps API 获取当前位置。
标签: ios iphone objective-c google-maps google-maps-sdk-ios