I have a SGV icon (.svg) that I want to use like cutom icon for map markers.
How should I proceed ? I didn't find anything on the subject.
If the SVG is part of your resources, you could simply add it to MarkerOptions by calling
val svgIcon = BitmapDescriptorFactory.fromResource(R.drawable.your_svg_name_here)
val marker = MarkerOptions().position(LatLng(latitude, longitude)).icon(svgIcon)
googleMap?.addMarker(marker)
If it isn't in your resources, just use another method of the BitmapDescriptorFactory.
Related
I'm using the Google maps utility library to generate an icon for my markers, and the setColor is not working, every color I set, is a different shade of blue, it's not my color, and it's also got a black stroke around, which I don't want.
this is the code:
for (place in location.locations) {
val locationPoz = LatLng(place.lat, place.long)
boundsBuilder.include(locationPoz)
//Here is the icon part
val icon = IconGenerator(requireContext())
icon.setColor(R.color.red)
val fIcon = icon.makeIcon("${place.price}€")
val marker = MarkerOptions()
.position(locationPoz)
.title(place.name)
.icon(BitmapDescriptorFactory.fromBitmap(fIcon))
.alpha(5f)
googleMap.addMarker(marker)
}
And this is how my map looks
I think you can only use one of the provided values in https://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/ui/IconGenerator.html
Try
~icon.setColor(IconGenerator.STYLE_RED)~
EDIT: I misread, I think. The STYLE_* values would have to be used like
icon.setStyle(IconGenerator.STYLE_RED)
That doesn't yet solve your problem of the border you don't want, so instead, you would need to provide your own background drawable with setBackground
In android map application, it shows tool-tip window for multiple route, the same way google map also shows that window. I was wondering whether that is a custom marker or a infoWindow over poly-line.
Does any body knows how to achieve this with android map-v2 integration?
Following image show my expectations to implement in android.
2020 Solution (Kotlin)
I wrote this little Kotlin extension function (simply add to your extension functions or anywhere in your code) to do exactly the job needed: It adds an info window half way on the polyline.
fun Polyline.addInfoWindow(map: GoogleMap, title: String, message: String) {
val pointsOnLine = this.points.size
val infoLatLng = this.points[(pointsOnLine / 2)]
val invisibleMarker =
BitmapDescriptorFactory.fromBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888))
val marker = map.addMarker(
MarkerOptions()
.position(infoLatLng)
.title(title)
.snippet(message)
.alpha(0f)
.icon(invisibleMarker)
.anchor(0f, 0f)
)
marker.showInfoWindow()
}
Use as follows:
polyline.addInfoWindow(map, "Title", "Message")
Example use:
polyline.addInfoWindow(map, route.distanceText, route.durationText)
In the Google Maps Android API it says that:
An info window displays text or images in a popup window above the map. Info windows are always anchored to a marker. Their default behavior is to display when the marker is tapped.
Therefore, you will either have to use another solution than just attaching an info window to the polyline. Maybe you can create an invisible marker at the location, the polyline has been clicked, on the fly which opens the info window.
In case someone is still looking for an answer, you can use bubble icons from the maps-utils library. It lets you create customized markers, that look just like infowindows. You can run a demo from here, but make sure you import is as a project when you run it: File->New->Import Project...
I'm trying show all my map makers on Here maps, but I don't want cluster them to a number, like image. I used Here maps app, markers not clustered Here Maps.
What should I do ?.
You can find information about it here.
You can use the ClusterLayer class.
ClusterLayer cl = new ClusterLayer();
If you want to customize the image use their ImageClusterStyle & ClusterTheme.
ImageClusterStyle imageCluster = new ImageClusterStyle(img);
ClusterTheme theme = new ClusterTheme();
theme.setStyleForDensityRange(2, 9, imageCluster);
cl.setTheme(theme);
I have my own offline map data in my app but only for a small region. Now I'd like to overlay this data onto my Google Map V2. This also already works. The only thing missing now is that GoogleMaps still overlays it's road names / city names above my tiles.
Is it possible to display a google map V2 in Android with MAP_TYPE_NORMAL and overlay custom tiles above roads?
TileOverlay overlay = map.addTileOverlay(new
TileOverlayOptions().tileProvider(provider).zIndex(2000));
The zIndex does't seem to help me here.
I think there is no way to display your tile-layer over the road names/city names.
How about display your offline map as Marker?
It should be displayed on the top.
try this link for https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/TileOverlay &
EXAMPLE :
GoogleMap map; // ... get a map.
TileProvider tileProvider; // ... create a tile provider.
TileOverlay tileOverlay = map.addTileOverlay(
new TileOverlayOptions().tileProvider(tileProvider));
Hope this helps.
As far as I know, you cannot place TileOverlays or GroundOverlays on top of labels. Your best option might be to use a different map type. This can be changed after the map has been created (i.e. in the onMapReady method by using the mMap.setMapType(...) method). Here are some possibilities:
MAP_TYPE_NORMAL + Custom Map Style
You can easily create your own map styles by using the Styling Wizard. It allows you to create a style that excludes labels entirely (among other things). Once you've created a style you like, you can copy the JSON code generated by that website and add it to the project file res/raw/style_json.json. The style can then be applied like this:
mMap.setMapType( GoogleMap.MAP_TYPE_NORMAL );
try
{
boolean success = mMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
getContext(), R.raw.style_json ) );
if( !success )
{
Log.e( TAG, "Style parsing failed." );
}
}
catch( Resources.NotFoundException e )
{
Log.e( TAG, "Can't find style. Error: ", e );
}
MAP_TYPE_NONE + Custom Map Tiles
If you need to have labels outside of your TileOverlay, you could add a second TileOverlay of non-Google map tiles (like those provided by OpenStreetMap). These typically include the labels within the map tiles themselves. So if your TileOverlay is added with a higher z-index, it will appear on top of these other map tiles!
Map Types Without Labels
MAP_TYPE_SATELLITE and MAP_TYPE_NONE don't include labels. If you don't need any map data outside of your TileOverlay, using MAP_TYPE_NONE will save on mobile data.
I am using Xamarin and am using the SimpleMapDemo and I have a question about setting a MarkerOptions object to have a different icon.
Here is my current code:
marker1.Icon(SetFeatureDrawable('Icon.png'));
This above code is not working.
May I please have some help to set the icon to be the icon that is in the Drawable folder that has the name of 'Icon.png'?
Thanks in advance
EDIT
Here is my code:
marker1.Icon(BitmapDescriptorFactory.FromResource(Resource.Drawable.monkey));
This is the error I am getting:
Non-invocable member 'Android.Gms.Maps.Model.MarkerOptions.Icon' cannot be used like a method
Here is my code to try and set the icon:
marker1.Icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.monkey);
This is the error I am getting:
CS0200: Property or indexer 'Android.Gms.Maps.Model.MarkerOptions.Icon' cannot be assigned to -- it is read only (CS0200)
Try this code instead:
marker1.InvokeIcon(SetFeatureDrawable('Icon.png'));
In general, Xamarin tries to bind the Java setter/getters to properties. In this case, although MarkerOption.icon looks like a property to C# eyes, it is in fact a Java method. In this case the binding has "translated" the property-like Java method to MarkerOption.InvokeIcon in an attempt to conform with C# design guidelines.
Try in this way:
double latitude = 0.0;
double longitude = 0.0;
MarkerOptions mapMarker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Your title will be here");
mapMarker .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon)));
mapView.addMarker(mapMarker );
Try this one, using this i can show custom icon from drawable resource as marker in map
MarkerOptions markerOptions = new MarkerOptions();
// Setting position on the MarkerOptions
markerOptions.SetPosition(lt);
markerOptions.InvokeIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pin));