Move marker with gps in google map android

前端 未结 8 793
悲&欢浪女
悲&欢浪女 2020-12-15 19:31

I want to make move of the marker in GOOGLE MAP while gps location changes just like in UBER app. I have found some solutions but unab

8条回答
  •  借酒劲吻你
    2020-12-15 20:17

    Use this:

    implement LocationListener ,GoogleMap.OnMyLocationChangeListener in your map activity and then use location change Listener

           @Override
        public void onMyLocationChange(Location location) { 
            //mMap.clear //if you want refresh map remove comment
            // Getting latitude of the current location
            double latitude = location.getLatitude();
    
            // Getting longitude of the current location
            double longitude =location.getLongitude();
    
            // Creating a LatLng object for the current location
            LatLng latLng = new LatLng(latitude, longitude); //your_text_view.settext(latitude+","+longtitudde)
    
            // Showing the current location in Google Map
          mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
            mMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.destination_marker)).position(latLng).title(maping_status));
    
            // Zoom in the Google Map
          mMap.animateCamera(CameraUpdateFactory.zoomTo(20));
        }
    

提交回复
热议问题