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));
Related
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.
I have built a music app and now I am trying to build a mapping feature more like Shazam's or Instagrams as follows:
Where initially, I am to drop a general marker on several points without actually showing all the activity in that location. Then on tapping that marker, the map will zoom in and other markers that are more specific will show, and so on..
Is there a tutorial available that I can follow the to achieve this effect in Android?
I have just found out that Google has a utility library that provides for marker clustering. The documentation can be found here https://developers.google.com/maps/documentation/android-api/utility/marker-clustering
You can create a method to add custom markers using this function:
private void drawCustomMarker(LatLng point) {
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(point);
markerOptions.title("SMS");
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.sms));
mMap.addMarker(markerOptions);
}
You can pass LatLng object where you want to drop the marker. I have used it in map click listener:
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
#Override
public void onMapLongClick(LatLng newlatLng) {
drawCustomMarker(newlatLng);
}
});
Hope it will help you..!
Im creating an app where users need to walk to a point on a map. But they need to find a route to the point by them selves.
Ive created a map with markers but by default if a user clicks on the marker a "start navigation" and "view in google maps" option is shown. Is it possible to disable these options ?
The options that are shown on marker click
This thing is called Map Toolbar. You can disable it by calling UiSettings.setMapToolbarEnabled(false):
GoogleMap map;
....... //init map
map.getUiSettings().setMapToolbarEnabled(false);
You can also define setMapToolbarEnabled() from the XML using the following property:
map:uiMapToolbar="false"
In kotlin you can do:
map.apply {
uiSettings.isMapToolbarEnabled = false
}
If anyone needs to do this in Google Maps v2, you set it in the map options instead of setting it on the map directly. So like this:
var mapOptions = new GoogleMapOptions().InvokeMapToolbarEnabled(false);
I'm developing an android project,in this project i have google map view and i use google map v2 . The problem is, i have some MarkerOption and i'm setting a utf8 string for them but the titles are shown as an empty string
here is my code for adding markers:
MarkerOptions marker = new MarkerOptions().position(pos).title("سلام");
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
googleMap.addMarker(marker);
how can i solve this?
thanks for any helps
you must set an English word then set your string :
MarkerOptions marker = new MarkerOptions().position(pos).title("TEST:"+"سلام");
You can add a unicode left-to-right mark ("\u200e") to your text, like:
.title("\u200e" + "سلام");
Marker startMarker = new Marker(mapView);
When I type this one to create the Marker is "new Marker(mapView); " red lined.
and i got this message in my headline -->The constructor Marker(MapView) is undefined<--
What is the problem ?
You have to import the OSMBonusPack, because it contains the right definition of Marker.
I had the same issue while following the wiki tutorial.
import org.osmdroid.bonuspack.overlays.Marker
Make sure to download the BonusPack and include the .jar into lib inside your project and link it inside your project properties.
What is the problem ?
It's because the constructor really doesn't exist.
Try this instead :
Marker startMarker = mapView.addMarker(new MarkerOptions().position(markerLatLng)); // markerLatLng is the position for your marker in the map. You can add more options to marker ...