Added everything according to the Getting Started guide. Map loads, and I can add GMSMarker
s to the map without problem. I've got a method to draw a polygon, and the app crashes every time.
根据入门指南添加了所有内容。地图加载,我可以毫无问题地将GMSMarkers添加到地图中。我有一个绘制多边形的方法,应用程序每次都会崩溃。
The method:
方法:
-(void)drawPolygon
{
GMSMutablePath* path = [[GMSMutablePath alloc] init];
[path addCoordinate:CLLocationCoordinate2DMake(-91.13343811039999, 42.6450805664)];
[path addCoordinate:CLLocationCoordinate2DMake(-91.0180969238,42.6452140808)];
[path addCoordinate:CLLocationCoordinate2DMake(-90.8977890015,42.6446838379)];
[path addCoordinate:CLLocationCoordinate2DMake(-90.89622497560001,42.6696586609)];
[path addCoordinate:CLLocationCoordinate2DMake(-90.8959732056,42.6752548218)];
[path addCoordinate:CLLocationCoordinate2DMake(-90.88994598390001,42.6732940674)];
GMSPolygon* poly = [GMSPolygon polygonWithPath:path];
poly.strokeWidth = 2.0;
poly.strokeColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
poly.fillColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4];
poly.map = _mapView; //CRASH!!
}
Here's a backtrace:
这是一个回溯:
thread #1: tid = 0x1c03, 0x0010ebde Maps`(anonymous namespace)::PolygonInstance::UpdateEntities(float, gmscore::base::reffed_ptr<gmscore::vector::Camera>, gmscore::renderer::EntityRenderer*, (anonymous namespace)::MarkupBehavior*) + 288, stop reason = EXC_BAD_ACCESS (code=2, address=0x4)
frame #0: 0x0010ebde Maps`(anonymous namespace)::PolygonInstance::UpdateEntities(float, gmscore::base::reffed_ptr<gmscore::vector::Camera>, gmscore::renderer::EntityRenderer*, (anonymous namespace)::MarkupBehavior*) + 288
frame #1: 0x00111f3c Maps`(anonymous namespace)::MarkupBehavior::Commit(gmscore::renderer::EntityRenderer*) + 978
frame #2: 0x0008aad2 Maps`gmscore::renderer::EntityRenderer::Draw(bool) + 634
frame #3: 0x000d6a46 Maps`-[GMSEntityRendererView draw] + 200
frame #4: 0x000d5a85 Maps`-[GMSEntityRendererView displayLinkFired:] + 33
frame #5: 0x00144399 Maps`-[GMSDisplayLink displayLinkFired:] + 351
frame #6: 0x00f9e2d2 QuartzCore`CA::Display::DisplayLink::dispatch(unsigned long long, unsigned long long) + 110
frame #7: 0x00f9e75f QuartzCore`CA::Display::TimerDisplayLink::callback(__CFRunLoopTimer*, void*) + 161
frame #8: 0x02519376 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
frame #9: 0x02518e06 CoreFoundation`__CFRunLoopDoTimer + 534
frame #10: 0x02500a82 CoreFoundation`__CFRunLoopRun + 1810
frame #11: 0x024fff44 CoreFoundation`CFRunLoopRunSpecific + 276
frame #12: 0x024ffe1b CoreFoundation`CFRunLoopRunInMode + 123
frame #13: 0x038167e3 GraphicsServices`GSEventRunModal + 88
frame #14: 0x03816668 GraphicsServices`GSEventRun + 104
frame #15: 0x012bfffc UIKit`UIApplicationMain + 1211
frame #16: 0x0000298d Maps`main(argc=1, argv=0xbffff3e0) + 141 at main.m:16
I'm not trying to use MapKit at all. No other OpenGL contexts have been created. Can anyone provide me with a working example of GMSPolygon? I believe my example follows the official example.
我根本不想使用MapKit。没有创建其他OpenGL上下文。任何人都可以为我提供GMSPolygon的工作示例吗?我相信我的例子遵循官方的例子。
Using SDK version 1.3.1. ARC is enabled. Single-View app using Storyboards. Pan/Zoom everything else works, just not shape drawing.
使用SDK版本1.3.1。 ARC已启用。使用Storyboard的单一视图应用程序。平移/缩放其他所有工作,只是不形状绘图。
3 个解决方案
#1
4
Have either of you found a solution to this issue? I am having the exact same problem, and even using the Google Maps SDK for iOS code verbatim it is still crashing. It crashes on the bolded item below:
有没有人找到解决这个问题的方法?我有完全相同的问题,甚至逐字使用谷歌地图SDK for iOS代码它仍然崩溃。它在下面的粗体项目上崩溃:
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
[path addCoordinate:CLLocationCoordinate2DMake(37.45, -122.0)];
[path addCoordinate:CLLocationCoordinate2DMake(37.45, -122.2)];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.2)];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
**GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];**
rectangle.map = mapView_;
EDIT: I have found the solution for this behavior:
编辑:我找到了这种行为的解决方案:
To correct the issue, simply wrap your current code in a dispatch block. Reason being, Google Maps SDK requires that all drawing events be done on the main thread. The below code works properly:
要解决此问题,只需将当前代码包装在调度块中。原因是,Google Maps SDK要求所有绘图事件都在主线程上完成。以下代码正常工作:
dispatch_async(dispatch_get_main_queue(), ^{
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
[path addCoordinate:CLLocationCoordinate2DMake(37.45, -122.0)];
[path addCoordinate:CLLocationCoordinate2DMake(37.45, -122.2)];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.2)];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
**GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];**
rectangle.map = mapView_;
});
#2
4
I was having the same issue then I found this workaround:
我遇到了同样的问题然后我发现了这个解决方法:
The workaround:
解决方法:
-
In XCode, go to Product > Scheme > Edit Scheme...
在XCode中,转到产品>方案>编辑方案...
-
Select the "Run" Tab on the left.
选择左侧的“运行”选项卡。
-
Select the "Options" sub-tab on the top.
选择顶部的“选项”子选项卡。
-
Change "GPU Frame Capture" from "Automatically Enabled" or "OpenGL ES" to either "Metal" or "Disabled".
将“GPU Frame Capture”从“Automatically Enabled”或“OpenGL ES”更改为“Metal”或“Disabled”。
#3
1
Edit
编辑
I had my latitude and longitude coordinates transposed as I built my path.
当我建立自己的道路时,我的纬度和经度坐标被调换了。
/Edit
/编辑
I have encountered the same bug. I am not running it from a background thread. I add a marker at the same time as the polygon
我遇到了同样的错误。我没有从后台线程运行它。我在多边形的同时添加了一个标记
marker.map = mapView_; // No problem
polygon.map = mapView_; // Crash
Researching further.
进一步研究。
#1
4
Have either of you found a solution to this issue? I am having the exact same problem, and even using the Google Maps SDK for iOS code verbatim it is still crashing. It crashes on the bolded item below:
有没有人找到解决这个问题的方法?我有完全相同的问题,甚至逐字使用谷歌地图SDK for iOS代码它仍然崩溃。它在下面的粗体项目上崩溃:
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
[path addCoordinate:CLLocationCoordinate2DMake(37.45, -122.0)];
[path addCoordinate:CLLocationCoordinate2DMake(37.45, -122.2)];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.2)];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
**GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];**
rectangle.map = mapView_;
EDIT: I have found the solution for this behavior:
编辑:我找到了这种行为的解决方案:
To correct the issue, simply wrap your current code in a dispatch block. Reason being, Google Maps SDK requires that all drawing events be done on the main thread. The below code works properly:
要解决此问题,只需将当前代码包装在调度块中。原因是,Google Maps SDK要求所有绘图事件都在主线程上完成。以下代码正常工作:
dispatch_async(dispatch_get_main_queue(), ^{
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
[path addCoordinate:CLLocationCoordinate2DMake(37.45, -122.0)];
[path addCoordinate:CLLocationCoordinate2DMake(37.45, -122.2)];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.2)];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
**GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];**
rectangle.map = mapView_;
});
#2
4
I was having the same issue then I found this workaround:
我遇到了同样的问题然后我发现了这个解决方法:
The workaround:
解决方法:
-
In XCode, go to Product > Scheme > Edit Scheme...
在XCode中,转到产品>方案>编辑方案...
-
Select the "Run" Tab on the left.
选择左侧的“运行”选项卡。
-
Select the "Options" sub-tab on the top.
选择顶部的“选项”子选项卡。
-
Change "GPU Frame Capture" from "Automatically Enabled" or "OpenGL ES" to either "Metal" or "Disabled".
将“GPU Frame Capture”从“Automatically Enabled”或“OpenGL ES”更改为“Metal”或“Disabled”。
#3
1
Edit
编辑
I had my latitude and longitude coordinates transposed as I built my path.
当我建立自己的道路时,我的纬度和经度坐标被调换了。
/Edit
/编辑
I have encountered the same bug. I am not running it from a background thread. I add a marker at the same time as the polygon
我遇到了同样的错误。我没有从后台线程运行它。我在多边形的同时添加了一个标记
marker.map = mapView_; // No problem
polygon.map = mapView_; // Crash
Researching further.
进一步研究。