Myst
Myst

Reputation: 177

android automatic title on red marker on Google Maps

I have a android map application where it track the user location and display it on the map. i make it so that there will be a title "you are here" that appear on top of the red marker. however, it did not appear on its own and i must tap on the red marker. and i could tap on any red marker and the title would move there and disappear on the previous one.

how do i make it so that it only appears on the latest red marker(latest location) on its own and cannot be removed?to show the user his current location.

the speed i set it at 1. i do not know whether it is good enough. the location stopped updating while i was not moving but it is still slow and inaccurate.

    public void onLocationChanged(Location myLocation) {
    System.out.println("speed " + myLocation.getSpeed());
    if(myLocation.getSpeed() > speed)
    {
        //show location on map.................
        //Get latitude of the current location
        double latitude = myLocation.getLatitude();
        //Get longitude of the current location
        double longitude = myLocation.getLongitude();
        //Create a LatLng object for the current location
        LatLng latLng = new LatLng(latitude, longitude);
        //Show the current location in Google Map
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        //Zoom in the Google Map
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
        googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).snippet("You are here!").title("You are here!"));

Upvotes: 0

Views: 1162

Answers (2)

Namrata
Namrata

Reputation: 1684

Try This:-

Marker pos = googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).snippet("You are here!").title("You are here!"));

instead of

   googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).snippet("You are here!").title("You are here!"));

Or Write this, it is very easy:-

locationMarker.showInfoWindow();

Upvotes: 2

Kumar Bibek
Kumar Bibek

Reputation: 9117

You can't really achieve this by using the existing API's on Android, without coding a lot of custom views and controls.

There's a nice library which you can use to customize the markers on your maps. Here's an example taken from it's website. It's called android-maps-utils

enter image description here

The link to the library on github.

https://github.com/googlemaps/android-maps-utils

And the website, where you can find a video and other examples.

http://googlemaps.github.io/android-maps-utils/

Upvotes: 1

Related Questions