开发者

How to move the marker(current marker) on google map as Device moves in android

开发者 https://www.devze.com 2023-04-05 14:09 出处:网络
how to moves marker(like dot) on google map as device moves (user moves)..... import android.content.Context;

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 My开发者_Python百科LocationOverlay {

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号