Changing colour of Markers - Google Map V2 Android

匆匆过客 提交于 2020-05-09 20:01:10

问题


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?


回答1:


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.




回答2:


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.




回答3:


{
    googleMap.addMarker(new MarkerOptions()
         .position(new LatLng(19.01062463, 73.01141475))
         .title("Point1").snippet("Speed=1.2")
         .icon(bitmapDescriptorFromVector(context, R.drawable.ic_icon)));
}

googleMap.addMarker(new MarkerOptions()
    .position(new LatLng(19.02369039, 73.00778391))
    .title("Point2")
    .snippet("Speed2=0.42").icon(bitmapDescriptorFromVector(context, R.drawable.ic_icon)));


来源:https://stackoverflow.com/questions/16598169/changing-colour-of-markers-google-map-v2-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!