在谷歌地图上拖动标记需要花费太多时间



我在谷歌地图api v2上工作,我想让我的标记可拖动为真,简单地说,我想把我的标记从一个位置拖到另一个位置,但是需要时间来关注那个标记。

下面是我的代码,请告诉我哪里做错了

活动:

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class DragMarker extends FragmentActivity implements OnMarkerDragListener {
    private static GoogleMap map;
    @Override
    protected void onCreate(Bundle saveInstance) {
        super.onCreate(saveInstance);
        setContentView(R.layout.activity_test_drag_marker);
        map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        map.setOnMarkerDragListener(this);
        //map.setOnMapLongClickListener(this);
        //      map.setOnMapClickListener(this);
        CameraPosition INIT = new CameraPosition.Builder().target(new LatLng(19.0222, 72.8666)).zoom(17.5F).bearing(300F) // orientation
                .tilt(50F) // viewing angle
                .build();
        // use map to move camera into position
        map.moveCamera(CameraUpdateFactory.newCameraPosition(INIT));
        //create initial marker
        map.addMarker(new MarkerOptions().position(new LatLng(19.0216, 72.8646)).draggable(true).title("Location").snippet("First Marker")).showInfoWindow();
    }
    @Override
    public void onMarkerDrag(Marker arg0) {
        // TODO Auto-generated method stub
    }
    @Override
    public void onMarkerDragEnd(Marker arg0) {
        // TODO Auto-generated method stub
        LatLng dragPosition = arg0.getPosition();
        double dragLat = dragPosition.latitude;
        double dragLong = dragPosition.longitude;
        Log.i("info", "on drag end :" + dragLat + " dragLong :" + dragLong);
        Toast.makeText(getApplicationContext(), "Marker Dragged..!", Toast.LENGTH_LONG).show();
    }
    @Override
    public void onMarkerDragStart(Marker arg0) {
        // TODO Auto-generated method stub
    }
    /*@Override
    public void onMapClick(LatLng arg0) {
        // TODO Auto-generated method stub
        map.animateCamera(CameraUpdateFactory.newLatLng(arg0));
    }*/
    /*@Override
    public void onMapLongClick(LatLng arg0) {
        // TODO Auto-generated method stub
        //create new marker when user long clicks
        map.addMarker(new MarkerOptions().position(arg0).draggable(true));
    }*/
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

放置标记:

Marker perth = mMap.addMarker(new MarkerOptions().position(PERTH).draggable(true));

//创建标记选项

           MarkerOptions options = new MarkerOptions();

//设置标记的位置

           options.position(point);

//设置标记为true

           options.draggable(true);

相关内容

  • 没有找到相关文章

最新更新