简体   繁体   English

在室内设置当前位置-Google Maps iOS SDK

[英]Set Current Location in Indoors - Google Maps iOS SDK

Now that I have added a ground overlay for my indoor map using Google Maps iOS sdk, can I set the blue dot(user current location) manually with code? 现在,我已经使用Google Maps iOS sdk为室内地图添加了地面叠加层,是否可以使用代码手动设置蓝点(用户当前位置)?

I can't seem to find a way to do so. 我似乎找不到办法。 Would be happy to see an example code snippet. 很高兴看到示例代码片段。

This may help 这可能会有所帮助

CLLocationCoordinate2D inspectionCenter = CLLocationCoordinate2DMake(markerLocation.coordinate.latitude, markerLocation.coordinate.longitude);
GMSMarker *marker = [[GMSMarker alloc] init];
                         marker.title = [NSString stringWithFormat:@""];
                         marker.position = inspectionCenter;
                         marker.appearAnimation = kGMSMarkerAnimationPop;
                         marker.map = mapView;
                         NSString *imageName=[NSString stringWithFormat:@"yourimage"];
                         marker.icon = [UIImage imageNamed:imageName];

Basically you need to check significant location changes, there can be a case where user is standing at a particular location for a minute and the NSTimer or the logic for 10 seconds which you are using will be called again and again. 基本上,您需要检查重大的位置更改,在某些情况下,用户可能会在特定位置站立一分钟,然后会反复调用您使用的NSTimer或逻辑10秒钟。 For this you need to check for significant location changes as follow. 为此,您需要按照以下步骤检查重要的位置更改。

if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];

locationManager.delegate = self;
//Configure Accuracy depending on your needs, default is kCLLocationAccuracyBest
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;

// Set a movement threshold for new events.
locationManager.distanceFilter = 500; // meters, set according to the required value.

[locationManager startUpdatingLocation];

You cannot do it totally with the Google maps SDK, you got to use the CLLocationManger framework to get the location updates. 您无法使用Google Maps SDK完全做到这一点,必须使用CLLocationManger框架来获取位置更新。

Initialize your locationManager to register for significant location changes and set up the delegate properly 初始化locationManager以注册重大的位置更改并正确设置委托

The Location Manger's delegate: 位置经理的代表:

- (void)locationManager:(CLLocationManager *)manager
  didUpdateLocations:(NSArray *)locations {
// If it's a relatively recent event, turn off updates to save power.
  CLLocation* location = [locations lastObject];
  NSDate* eventDate = location.timestamp;
  NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
  if (abs(howRecent) < 15.0) {
  // Update your marker on your map using location.coordinate by using the GMSCameraUpdate object

  GMSCameraUpdate *locationUpdate = [GMSCameraUpdate setTarget:location.coordinate zoom:YOUR_ZOOM_LEVEL];
  [mapView_ animateWithCameraUpdate:locationUpdate];


}

This might help. 这可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM