如何在Android地图中移动标记

时间:2018-08-17 06:14:05

标签: android maps

我在android中遇到关于地图的问题,我只想在当前位置移动时移动徽标,即当我在地图中移动时,也应该移动地图中的徽标,有人可以帮助我解决吗代码这是我的代码,

感谢andvance

public void onLocationChanged(Location location) {
    mLastLocation = location;
    if (mCurrLocationMarker != null) {
        mCurrLocationMarker.remove();
    }


    // toPosition = new LatLng(Double.parseDouble(store_latitude), Double.parseDouble(store_longitude));
    toPosition = new LatLng(location.getLatitude(), location.getLongitude());

    markerOptions = new MarkerOptions();
    markerOptions.position(toPosition);
    markerOptions.title("Driver Location");
    markerOptions.snippet(store_address1 + " " + store_city);
    markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.driver_annot));
    mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);
    mCurrLocationMarker.showInfoWindow();



    // Customer location marker
    toPosition22 = new LatLng(Double.parseDouble(customer_latitude), Double.parseDouble(customer_longitude));
    markerOptions1 = new MarkerOptions();
    markerOptions1.position(toPosition22);
    markerOptions1.snippet(cusomer_address1 + " " + cusomer_city);
    if (str_status.equals("customer")) {
        markerOptions1.title("Delivery Location");

        markerOptions1.icon(BitmapDescriptorFactory.fromResource(R.drawable.customer_annot));
    } else {
        markerOptions1.title("Pickup Location");

        markerOptions1.icon(BitmapDescriptorFactory.fromResource(R.drawable.store_annot));

    }
    mCurrLocationMarker1 = mGoogleMap.addMarker(markerOptions1);
    mCurrLocationMarker1.showInfoWindow();
    //move map camera
    mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(toPosition));
    mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(15));

    GetRouteTask getRoute = new GetRouteTask();
    getRoute.execute();

    timer.scheduleAtFixedRate(new Task(), 0, 10000);//10 sec=10000


    //stop location updates
    if (mGoogleApiClient != null) {
        LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
    }
    //  new NextLine().execute();

}

1 个答案:

答案 0 :(得分:0)

您可以这样做

 mMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
                    @Override
                    public void onMarkerDragStart(Marker marker) {
                        changeEditText(marker, databaseReference, geocoder);


                    }

                    @Override
                    public void onMarkerDrag(Marker marker) {
                        changeEditText(marker, databaseReference, geocoder);

                    }

                    @Override
                    public void onMarkerDragEnd(Marker marker) {
                        changeEditText(marker, databaseReference, geocoder);
                    }
                });