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

发布于 2024-12-04 20:01:32 字数 1228 浏览 0 评论 0原文

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

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 moves marker(like dot) on google map as device moves (user moves).....

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌伤ぢ 2024-12-11 20:01:32

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

如何在 Android 中显示带标记的地图

要在地图上移动标记,您需要在类中创建静态方法,该方法扩展 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();
}

扩展 Overlay 类的自定义覆盖类一样。

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 类在地图上绘制图像。

check my post answer there was link.

how to display map in android with marker

for moving marker on map you need to create the static method in the your class which extends the MapActivity like

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

your custom overlay class which extends the Overlay class.

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

here to display your drawable image display using Bitmap class to draw image on map.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文