Google Maps iOS SDK move “My Location” button to bottom left hand corner

前端 未结 6 2114
南方客
南方客 2020-12-13 22:27

Using the Google Maps for iOS SDK, the \"My Location\" button is by default placed in the bottom right hand corner:

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 23:02

    The easiest way to solve this is to change the frame and autoresizing mask of the button right after the map view is created.

    UIButton* myLocationButton = (UIButton*)[[mapView_ subviews] lastObject];
    myLocationButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin;
    CGRect frame = myLocationButton.frame;
    frame.origin.x = 5;
    myLocationButton.frame = frame;
    

    EDIT: Sorry, I placed the button in the top right corner. Updated my code to place it in the bottom left hand corner.

    Note: there is currently no API from Google to get the location button. The first line may not work in future releases of the SDK.

    You also should create a feature request here.

    Another option is to create the button yourself and add it as a subview to the map. The button handler code is fairly easy:

      CLLocation *location = mapView_.myLocation;
      if (location) {
        [mapView_ animateToLocation:location.coordinate];
      }
    

提交回复
热议问题