我在我的应用程序中使用的是最新的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];
}
最佳答案
我已经在Google Maps SDK for iOS bug上发布了我的Chris代码的重做版本。
该解决方案涉及对克里斯的代码的两项更改:
viewDidLoad
,