Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing colour of Markers - Google Map V2 Android

I'm having a little trouble understanding how to change the colour of a marker in an Android Google Map project.

My code for a Marker is:

googlemap.addMarker(new MarkerOptions()     .position(new LatLng( 65.07213,-2.109375))     .title("This is my title"))     .setSnippet("and snippet");     .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))); 

I get this error when I put in the .icon code on the last line, otherwise the .position, .title and .setSnippet work just fine and are visible on the map.

Cannot invoke icon(BitmapDescriptor) on the primitive type void

These get imported aswell:

import com.google.android.gms.maps.model.BitmapDescriptor; import com.google.android.gms.maps.model.BitmapDescriptorFactory; 

But nothing else is added in. Have I missed a vital part?

like image 867
user1977908 Avatar asked May 16 '13 21:05

user1977908


People also ask

How do you change the color of a marker on Google Maps?

To edit the marker color, click or tap on the marker icon. When you do that, you can change both the color of the marker and its style. Go for the color or style you want to change and then click OK to see the effect. Click on the button labeled Done to save your new marker color settings.


2 Answers

You have a couple of characters wrong there. Compare your code to this:

googlemap.addMarker(new MarkerOptions()     .position(new LatLng( 65.07213,-2.109375))     .title("This is my title")     .snippet("and snippet")     .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))); 

Removed ) on third line, changed setSnippet to snippet and removed ; on forth line.

like image 51
MaciejGórski Avatar answered Oct 02 '22 18:10

MaciejGórski


The problem is the semicolon ";" on the end of the line

.setSnippet("and snippet"); 

If you delete the semicolon making it

.setSnippet("and snippet") 

It should work.

like image 43
HexAndBugs Avatar answered Oct 02 '22 17:10

HexAndBugs