【问题标题】:GMSMarker not show on button click run timeGMSMarker 未在按钮单击运行时显示
【发布时间】:2019-08-25 18:23:06
【问题描述】:

我正在尝试在运行时添加标记,然后按下按钮。按钮方法调用和代码运行,但地图上未显示标记。如果我在添加子视图时间时添加标记然后完美显示,但我需要在按钮按下时使用不同的大小写。

按钮点击(地图上不显示任何制造商)

-(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:@"pinIcon"];
    london.map = self.mapView;
 });
}

添加时间(显示标记)

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:self.currentLocation.coordinate.latitude
                                                        longitude:self.currentLocation.coordinate.longitude
                                                             zoom:16];

self.mapView = [GMSMapView mapWithFrame:self.view.frame camera:camera];
self.mapView.myLocationEnabled = YES;
[self.mapView setDelegate:self];
self.mapView.mapType = kGMSTypeSatellite;    
[self.googleMapView addSubview:self.mapView];

self.marker = [[GMSMarker alloc] init];
self.marker.position = CLLocationCoordinate2DMake(43.649580, -79.385440);
self.marker.title = @"Toronto";
self.marker.snippet = @"Canada";
self.marker.map = self.mapView;

【问题讨论】:

  • 什么是googleMapView?为什么要向其中添加 Google 地图视图?
  • ViewController 中的子视图。
  • 和self.view一样
  • 只有在 viewdidload 中你可以添加伦敦标记,但是当按钮按下标记应该被隐藏时它应该被隐藏,不要尝试这种方式
  • 按下按钮后标记不显示的问题

标签: ios objective-c google-maps-api-3


【解决方案1】:

请在演示项目中使用此代码,然后签入您自己的项目

@IBOutlet var mapView: GMSMapView!
//use the following code in you button action
let state_marker = GMSMarker()
    let long = //Double long
    let lat = //Double lat
    state_marker.position = CLLocationCoordinate2D(latitude: lat!, longitude: long!)
    state_marker.map = mapView
     // add in subview if you want to add, or place a view on story board and assign GMSMapView to this

【讨论】:

  • 在 swift 中尝试演示,可能是你的代码有问题,我不擅长 Objective-C
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-19
  • 2021-11-02
  • 2021-04-07
  • 1970-01-01
  • 1970-01-01
  • 2013-05-11
  • 1970-01-01
相关资源
最近更新 更多