gpt4 book ai didi

android - 如何在设备在 android 中移动时在谷歌地图上移动标记(当前标记)

转载 作者:行者123 更新时间:2023-11-29 22:20:14 25 4
gpt4 key购买 nike

如何在设备移动(用户移动)时在谷歌地图上移动标记(如点)....

import android.content.Context;
import android.widget.Toast;

import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;

// This class subclasses (extends) MyLocationOverlay so that we can override its dispatchTap method
// to handle tap events on the present location dot.

public class MyMyLocationOverlay extends MyLocationOverlay {

private Context context;

public MyMyLocationOverlay(Context context, MapView mapView) {
super(context, mapView);
this.context = context; // Will need this for Toast argument below
}

// Override the dispatchTap() method to toggle the data display on and off when
// the present location dot is tapped. Also display a short Toast (transient message) to the
// user indicating the display status change.

@Override
protected boolean dispatchTap(){
if(DisplayOverlay.showData){
Toast.makeText(context, "Suppressing data readout", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context,"Display data readout", Toast.LENGTH_SHORT).show();
}
// Toggle the GPS data display
DisplayOverlay.showData = ! DisplayOverlay.showData;
return true;
}

最佳答案

检查我的帖子答案有链接。

how to display map in android with marker

要在 map 上移动标记,您需要在类中创建静态方法来扩展 MapActivity,例如

private static GeoPoint markerPoint;

public static void updateLocation(Location location){
lat = location.getLatitude();
lng = location.getLongitude();

// now use this lat/lng value to convert into the GeoPoint object

markerPoint = new GeoPoint(lat * 1e6, lng * 1e6);
mapview.invalidate();
}

您的自定义覆盖类,它扩展了覆盖类。

public void draw(Canvas canvas, MapView mapView, boolean Shadow){
Point screenPts = new Point();
mapView.getProjection().toPixels(markerPoint, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.cur_loc_1);
canvas.drawBitmap(bmp, screenPts.x-(xCurLocOffset), screenPts.y-yCurLocOffset, null);
}

此处使用 Bitmap 类在 map 上绘制图像来显示可绘制图像显示。

关于android - 如何在设备在 android 中移动时在谷歌地图上移动标记(当前标记),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7428865/

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