How do I move marker along with moving of Google Map in iOS?

前端 未结 4 1881
一个人的身影
一个人的身影 2020-12-24 15:37

I am displaying a marker in a particular place, along with displaying the current address in the address label on Google Maps.

Now, I want to change the location by

4条回答
  •  天涯浪人
    2020-12-24 16:11

    There is one trick that can help you out here. Instead of using a GMSMarker here, put an image pointing to the center, over your Google MapView.

    You can easily find the coordinates of Map's center using this :

    double latitude = mapView.camera.target.latitude;
    double longitude = mapView.camera.target.longitude;
    

    Or this

    GMSCoordinateBounds *bounds = nil;
    bounds = [[GMSCoordinateBounds alloc] initWithRegion: visibleRegion];
    
    CLLocationCoordinate2D centre = CLLocationCoordinate2DMake(
                                                               (bounds.southWest.latitude + bounds.northEast.latitude) / 2,
                                                               (bounds.southWest.longitude + bounds.northEast.longitude) / 2);
    

    Now you can get the location address by using Geocoding API by google.

    Here is the reference : https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_geocoder

    You can refresh Address when this delegate method is called :

    - (void) mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position 
    

    Hope this helps.

提交回复
热议问题