Android programming, mapview location-overlay: how to change the default blue location dot, with another image

StackOverflow https://stackoverflow.com/questions/10200074

I need to work out how to change the default 'my location' blue dot with an image, that will also act in the same fashion as a compass pointing the direction of travel. This can be worked out by the device compass or by detecting direction of travel from GPS

I've done some Googling but so far only found a reference for the method of changing the dot on the iPhone, and I am working with Android...

I'd appreciate some support and guidance in this

Kind regards

Nick

In OnCreate:

        LocationManager locman = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        locman.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 2, locationListener); 

        //Adds a current location overlay to the map 'mapView' and turns on the map's compass

        MyLocation myLocationOverlay = new MyLocation(this, mapView);
        mapView.getOverlays().add(myLocationOverlay);
        myLocationOverlay.enableMyLocation();
        myLocationOverlay.enableCompass();

        mapView.getOverlays().add(myLocationOverlay);
        mapView.postInvalidate();


In OnLocationChanged:


    dbllatitude = locFromGps.getLatitude();
            dbllongitude = locFromGps.getLongitude();
            dblaltitude = locFromGps.getAltitude();


    bearing = locFromGps.getBearing(); 


         strlatitude = Double.toString(dbllatitude);
            strlongitude = Double.toString(dbllongitude);
            dblaltitude = (dblaltitude / 0.3048); 

            LocationText.setText("Your Location: Latitude " + dbllatitude + " Longitude: " +dbllongitude + " Altitude " + dblaltitude);



            boolean hasbearing = locFromGps.hasBearing();


            if (hasbearing =  false) {

                Toast.makeText(getApplicationContext(), "No bearing", Toast.LENGTH_SHORT).show();

            }
            else
            {
                Toast.makeText(getApplicationContext(), "I HAZ bearing: " + bearing, Toast.LENGTH_SHORT).show();
            }
            MyLocation.mOrientation = bearing;

有帮助吗?

解决方案 2

For anyone else looking to get similar functionality of rotating the user location icon see the post at:

Android getbearing only returns 0.0. Trying to use to rotate current location icon

the location manager .getbearing() comes in handy

Regards

Nick

其他提示

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top