ROTATE Google-Map to display my real-time DIRECTION

后端 未结 1 945
自闭症患者
自闭症患者 2021-01-02 02:28

I am using the Google Maps Android API v2 where I display my Device location as a GoogleMap Marker on a Map. I have a listener (LocationServices.FusedLocationApi.requestLoc

相关标签:
1条回答
  • 2021-01-02 03:20

    I was guessing how is posible that the Google Map API does not provide such common visual effect desire. I was wrong... it's called BEARING.

    private void updateCameraBearing(GoogleMap googleMap, float bearing) {
        if ( googleMap == null) return;
        CameraPosition camPos = CameraPosition
                .builder(
                        googleMap.getCameraPosition() // current Camera
                )
                .bearing(bearing)
                .build();                   
        googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(camPos)); 
    }
    

    Since I setup my location changes to be notified every 2 seconds...

        mLocationRequest = LocationRequest.create()
                            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                            .setInterval(POLLING_FREQ_2SECONDS)
                            .setFastestInterval(FASTEST_UPDATE_FREQ_2_SECONDS)
    

    I use that same place to process the new location as well as to update the Camera (new BEARING):

    public void onLocationChanged(Location location) {
    
     // ... process location
    
     updateCameraBearing(googleMap, location.getBearing());
    }
    

    TESTED + WORKING = DONE!

    0 讨论(0)
提交回复
热议问题