我使用按钮在特定位置添加图钉,并且我的 map 已经加载并显示在屏幕上。然后按下按钮甚至不响应标记创建和分配坐标。

-(IBAction)addingMarkerOnMap:(id)sender
{
    CLLocationCoordinate2D position = CLLocationCoordinate2DMake(51.5, -0.127);
    GMSMarker *london = [GMSMarker markerWithPosition:position];
    london.title = @"London";
    london.icon = [UIImage imageNamed:@"Standard"];
    london.map = self.mapView;

}

最佳答案

试试这个代码:

-(IBAction)addingMarkerOnMap:(id)sender
{
  dispatch_async(dispatch_get_main_queue(), ^{
    CLLocationCoordinate2D position = CLLocationCoordinate2DMake(51.5, -0.127);
    GMSMarker *london = [GMSMarker markerWithPosition:position];
    london.title = @"London";
    london.icon = [UIImage imageNamed:@"Standard"];
    london.map = self.mapView;
 });
}

关于ios - 添加后,GMSMarker未显示在 map 上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55241174/

10-12 01:43