gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:41:14 31 4
gpt4 key购买 nike

我正在使用 google map api v2,我想让我的标记可拖动为真,只是我想将我的标记从一个位置拖放到另一个位置,但要花时间关注那个标记。

以下是我的代码,请大家指出哪里做错了

Activity :

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));

关于android - 在谷歌地图上拖动标记需要太多时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24551966/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com