开发者

How to change the pin of Google map in android when user moves?

开发者 https://www.devze.com 2023-04-02 10:23 出处:网络
In my android app I need to show the user\'s current location in Google map. I can change the map in onLocationChange() method. But the thing is I want to change the pin also. How can I move the pin开

In my android app I need to show the user's current location in Google map. I can change the map in onLocationChange() method. But the thing is I want to change the pin also. How can I move the pin开发者_JS百科 when user move on ?

Thanks in advance !


you need to pass the lat/lng to the MapActivity class and then get set into the GeoPoint object. Also you have add Overlay(once when first time you display the pin on map) into your map and in your that class which was implement by the overlay you have to draw the pin point and pass the the GeoPoint object in that

private void drawFreeMarker(Canvas canvas, MapView mapView, boolean shadow) {
            Point screenPts = new Point();
            mapView.getProjection().toPixels(tempPoint, screenPts);
            //---add the marker---
            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.bluepin_38);
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y, null);
        }

here I have implement like this way in my application tempPoint is the GeoPoint which was contain the lat/lng value and when the location change you have to pass that value to the MapActivity and invalidate the map so that's way you can move your pin


You need onLocationChange to remove from mapView previus overlay and add second with a marker...I presume that you are using MyLocationOverlay class????

0

精彩评论

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