GMSMarker不在按钮单击运行时显示

时间:2019-04-04 05:23:26

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

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

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

-(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;

1 个答案:

答案 0 :(得分:0)

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

@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