Nick
Nick

Reputation: 51

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

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;

Upvotes: 0

Views: 1427

Answers (2)

Nick
Nick

Reputation: 51

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

Upvotes: 0

MH.
MH.

Reputation: 45503

Subclass MyLocationOverlay, override the drawMyLocation(...) method and draw your image using the provided parameters. There are several examples here on SO and blogs that can help you on your way, e.g.:

Upvotes: 1

Related Questions