简体   繁体   中英

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?

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. 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.

Initialize your locationManager to register for significant location changes and set up the delegate properly

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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