Question

I am using the latest GoogleMaps iOS SDK in my application and after the latest iOS update, 7.0.3, it started becoming unresponsive after first touch. Let me expand on this. After the first touch on the map, the map becomes unresponsive. At first, you can pinch zoom, drag, swipe, and everything else but after that first touch, it no longer works. This started happening after Apple updated their iOS. If I use the iOS6 simulator, I can can do all the gestures even after the first touch. I don't know if this is because of the iOS update or something is wrong with my code. If anyone has any suggestions or has gone through something like this that could guide me, that could be greatly appreciated. Thanks in advance.

Followed the website instructions here: (https://developers.google.com/maps/documentation/ios/start#adding_the_google_maps_sdk_for_ios_to_your_project)

and it works on iOS6 and was working on iOS7 before. MapsViewController.m

#import "MapsViewController.h"
#import <GoogleMaps/GoogleMaps.h>
@interface MapsViewController ()
@end
@implementation MapsViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.storeNamesArray        = [[NSMutableArray alloc] init];
    self.storePricesArray       = [[NSMutableArray alloc] init];
    self.storeLatitudeArray     = [[NSMutableArray alloc] init];
    self.storeLongitudeArray    = [[NSMutableArray alloc] init];
    self.priceTypeArray         = [[NSMutableArray alloc] init];

    dispatch_async(dispatch_get_main_queue(), ^{ NSData *data = 
    [NSData dataWithContentsOfURL:[NSURL URLWithString:
    [NSString stringWithFormat: @"http://www.someurl.com/mobile-api"]]]; 
    [self performSelectorOnMainThread:@selector(fetchData:) withObject:data
    waitUntilDone:YES]; });
}

-(void)fetchData:(NSData *)responseData
{
    if (responseData)
    {
        NSError *error;
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
        NSDictionary *stores =[json objectForKey:@"stores"];
        for(NSDictionary *location in stores)
        {
            [self.storeNamesArray addObject:[location objectForKey:@"name"]];
            [self.storePricesArray addObject:[location objectForKey:@"price"]];
            [self.storeLatitudeArray addObject:[location objectForKey:@"latitude"]];
            [self.storeLongitudeArray addObject:[location objectForKey:@"longitude"]];
            [self.priceTypeArray addObject:[location objectForKey:@"price_type"]];
        }
    }
    double lat = 0.0;
    double lon = 0.0;
    GMSCameraPosition *camera;
    if(self.currentLocationArray.count !=0)
    {
        lat = [self.currentLocationArray[0] doubleValue];
        lon = [self.currentLocationArray[1] doubleValue];
        camera = [GMSCameraPosition cameraWithLatitude:lat longitude:lon zoom:12];
    }
    else
    {
        lat = [self.storeLatitudeArray[0] doubleValue];
        lon = [self.storeLongitudeArray[0] doubleValue];
        camera = [GMSCameraPosition cameraWithLatitude:lat longitude:lon zoom:9];
    }
    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    for(int i=0; i<self.storeNamesArray.count; i++)
    {
        GMSMarker *marker = [[GMSMarker alloc] init];
        marker.title = self.storeNamesArray[i];
        marker.snippet = [NSString stringWithFormat:@"%@ $%@", self.priceTypeArray[i], self.storePricesArray[i]];
        marker.position = CLLocationCoordinate2DMake([self.storeLatitudeArray[i] doubleValue], [self.storeLongitudeArray[i] doubleValue]);
        marker.map = mapView;
    }
    if(self.currentLocationArray.count !=0)
    {
        GMSMarker *currentMarker = [[GMSMarker alloc] init];
        currentMarker.title = @"Current Location";
        currentMarker.snippet = @"You are here";
        currentMarker.position = CLLocationCoordinate2DMake(lat, lon);
        currentMarker.map = mapView;
        currentMarker.icon = [UIImage imageNamed:@"temp_userLocation"];
        mapView.selectedMarker = currentMarker;
    }
    CGRect newFrame = self.view.bounds;
    newFrame.size.height = frame.size.height / 2;
    mapView.frame = newFrame;
    mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
    mapView.delegate = self;
    [self.view addSubview:mapView];
}
Was it helpful?

Solution

I've published my reworked version of Chris's code on the Google Maps SDK for iOS bug.

The solution involved two changes to Chris's code:

  1. Migrate the Google Map instantiation to viewDidLoad,
  2. Push the network traffic from the Main (UI) thread to a background thread.

OTHER TIPS

I don't know if that's the case here but I had same issue with URLWithString function appears only on iOS 7.0.3, I assume Apple has change the characters this function can use so if it returns nil this is your solution.

What I did is using this function to create the string before using it with URLWithString:

-(NSString *) URLEncodeString:(NSString *) str // New to fix 7.0.3 issue //
{

    NSMutableString *tempStr = [NSMutableString stringWithString:str];
    [tempStr replaceOccurrencesOfString:@" " withString:@"+" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [tempStr length])];


    return [[NSString stringWithFormat:@"%@",tempStr] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

On your case just change the line to this one:

dispatch_async(dispatch_get_main_queue(), ^{ NSData *data = 
[NSData dataWithContentsOfURL:[NSURL URLWithString:[self URLEncodeString: [NSString stringWithFormat: @"http://www.someurl.com/mobile-api"]]]]; 
[self performSelectorOnMainThread:@selector(fetchData:) withObject:data
waitUntilDone:YES]; });

Hope that would help you too.

insert this code in viewDidLoad method

-(void)viewDidLoad {

[super viewDidLoad];

// iOS7 
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

.... your codes

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top