I downloaded the latest Google Maps for iOS SDK, integrated with my project per the documentation. The map shows up fine. I have a marker who position I update every one sec in a thread. When the marker starts to update on the map, the map becomes very unresponsive. Zoom, pan etc take several seconds giving the perception that the map isn't working. Can some one please help?
A second question: When I don't update the UI, I am able to zoom, pan etc. At that time, the map I overlay'ed on the google maps resizes or moves around even though I am setting the coordinates where I want to anchor the image. How do I stop that and keep the map anchored?
ViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <GoogleMaps/GoogleMaps.h>
@interface ViewController : UIViewController <CLLocationManagerDelegate, GMSIndoorDisplayDelegate, GMSMapViewDelegate>
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@property int counter;
@property (nonatomic, strong) GMSMapView *mapView;
@property (nonatomic, strong) GMSMarker *myMarker;
@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, strong) CLLocationCoordinate2D location;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.295210
longitude:-124.032841
zoom:10.5];
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.mapView.delegate = self;
self.view = self.mapView;
[self.mapView setMapType:kGMSTypeHybrid];
/* Location Manager stuff */
}
- (void) viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self stopSending];
}
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self stopSending];
}
- (void) overlapMap {
self.mapView.mapType = kGMSTypeNormal;
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(40.295048, -124.033110);
CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(40.295385, -124.032801);
GMSGroundOverlay *overlay = [self setGroundOverlayWithSouthWestCoordinate:southWest AndNorthEastCoordinate:northEast AndImage:[UIImage imageNamed:@"floorplan.png"]];
overlay.map = self.mapView;
[self.mapView animateToCameraPosition:[GMSCameraPosition
cameraWithLatitude:40.295210
longitude:-124.032951
zoom:30]];
[self.mapView setUserInteractionEnabled:true];
[self showMarkers];
}
- (void) showMarkers {
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateMarkerDetails) userInfo:nil repeats:YES];
}
- (void) updateMarkerDetails {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
CLLocationCoordinate2D location = [self getLocation];
if (CLLocationCoordinate2DIsValid(location) {
self.myMarker = [GMSMarker markerWithPosition:location];
self.myMarker.map = self.mapView;
self.osLocation.map = self.mapView;
}
[self.mapView setSelectedMarker:self.myMarker];
/* some code with the marker title and subtitle*/
dispatch_async(dispatch_get_main_queue(), ^{
[self.myMarker setPosition:location];
});
});
}
- (void) clearMap {
self.myMarker.map = nil;
self.osLocation.map = nil;
[self.timer invalidate];
self.timer = nil;
}
- (CLLocationCoordinate2D) getLocation {
return self.location;
}
/*
Location Manager related code
Some other proprietary code
*/
@end