2

我在我的应用程序中使用最新的 GoogleMaps iOS SDK,在最新的 iOS 更新 7.0.3 之后,它在第一次触摸后开始变得无响应。让我对此进行扩展。第一次触摸地图后,地图变得无响应。起初,您可以捏缩放、拖动、滑动和其他所有操作,但在第一次触摸之后,它就不再起作用了。这在 Apple 更新他们的 iOS 之后开始发生。如果我使用 iOS6 模拟器,即使在第一次触摸之后,我也可以完成所有手势。我不知道这是因为 iOS 更新还是我的代码有问题。如果有人有任何建议或经历过类似的事情可以指导我,那将不胜感激。提前致谢。

遵循此处的网站说明:(https://developers.google.com/maps/documentation/ios/start#adding_the_google_maps_sdk_for_ios_to_your_project

它适用于iOS6,之前也适用于iOS7。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];
}
4

3 回答 3

1

我已经在Google Maps SDK for iOS bug上发布了我修改后的 Chris 代码版本。

该解决方案涉及对 Chris 代码的两项更改:

  1. 将 Google Map 实例化迁移到viewDidLoad,
  2. 将网络流量从主 (UI) 线程推送到后台线程。
于 2013-11-14T07:03:08.457 回答
0

我不知道这里是否是这种情况,但我对 URLWithString 函数有同样的问题,它只出现在 iOS 7.0.3 上,我假设 Apple 已经更改了这个函数可以使用的字符,所以如果它返回 nil,这就是你的解决方案。

我所做的是在将它与 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];
}

在您的情况下,只需将行更改为这一行:

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]; });

希望这对你也有帮助。

于 2013-11-06T20:13:05.373 回答
-1

在 viewDidLoad 方法中插入此代码

-(无效)viewDidLoad {

[super viewDidLoad];

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

.... your codes

}

于 2013-11-02T23:05:13.267 回答