gpt4 book ai didi

android - 无法解析方法 getProjection() 和 getMapCenter()

转载 作者:行者123 更新时间:2023-11-30 01:21:49 26 4
gpt4 key购买 nike

我正在实现长按以在 mapview 上获取 latlang,我提到了this教程。但我收到错误

这是我的代码:

import com.google.android.gms.vision.barcode.Barcode;
public class MyCustomMapView extends MapView {

public interface OnLongpressListener {
public void onLongpress(MapView view, Barcode.GeoPoint longpressLocation);
}
static final int LONGPRESS_THRESHOLD = 500;
private Barcode.GeoPoint lastMapCenter;
private Timer longpressTimer = new Timer();
private MyCustomMapView.OnLongpressListener longpressListener;

public MyCustomMapView(Context context) {
super(context);
}

public void setOnLongpressListener(MyCustomMapView.OnLongpressListener listener) {
longpressListener = listener;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
handleLongpress(event);

return super.onTouchEvent(event);
}
private void handleLongpress(final MotionEvent event) {

if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Finger has touched screen.
longpressTimer = new Timer();
longpressTimer.schedule(new TimerTask() {
@Override
public void run() {
Barcode.GeoPoint longpressLocation = getProjection().fromPixels((int)event.getX(),
(int)event.getY()); <--here -->

longpressListener.onLongpress(MyCustomMapView.this, longpressLocation);
}

}, LONGPRESS_THRESHOLD);

lastMapCenter = **getMapCenter()**;
}

if (event.getAction() == MotionEvent.ACTION_MOVE) {

if (!getMapCenter().equals(lastMapCenter)) {
longpressTimer.cancel();
}

lastMapCenter = getMapCenter();<-- here -->
}

if (event.getAction() == MotionEvent.ACTION_UP) {
longpressTimer.cancel();
}

if (event.getPointerCount() > 1) {
longpressTimer.cancel();
}
}
}

这里我的 getProjection() 和 getMapCenter() 无法解析,我想知道为什么会这样,这个方法是否已被弃用,或者我必须使用什么方法来代替,

而且我还想知道为什么它是 barcode.GeoPoint,为什么我的程序导入

import com.google.android.gms.vision.barcode.Barcode;     instead of 
import com.google.maps.GeoPoint;

最佳答案

您可以实现 GoogleMap.OnMapClickListenerGoogleMap.OnMapLongClickListener 来实现这一点

public class CreateFenceActiviy extends AppCompatActivity implements GoogleMap.OnMapClickListener, GoogleMap.OnMapLongClickListener{
private GoogleMap mGoogleMap;
private SupportMapFragment mMapFragment;
private ArrayList<double[]> mLatLongArray =null;
private Polygon mPolygon;
private PolygonOptions mPolygonOptions;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_fence_activity);
mLatLongArray = new ArrayList<double[]>();
if (mGoogleMap == null) {
mMapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_create_fence));
mGoogleMap = mMapFragment.getMap();
mGoogleMap.setOnMapClickListener(this);
mGoogleMap.setOnMapLongClickListener(this);
mGoogleMap.setOnMarkerClickListener(this);
isMarkerClicked = false;
}

}
@Override
public void onMapClick(LatLng point) {
if(mGoogleMap != null){
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(point));
isMarkerClicked = false;
}
}

@Override
public void onMapLongClick(LatLng point) {
if(mGoogleMap != null) {
mGoogleMap.addMarker(new MarkerOptions().position(point).title(point.toString()));
double latitudeNew = point.latitude;
double longitude = point.longitude;
mLatLongArray.add(new double[]{latitudeNew, longitude});
isMarkerClicked = false;
}
}
}

map View 的 XML 将包含此组件

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map_create_fence"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

关于android - 无法解析方法 getProjection() 和 getMapCenter(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36981171/

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