The constructor Marker(MapView) is undefined ?? Why ?? - android

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 ...

Related

Android Map : How to cutomize Marker icon with SVG file?

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.

Android: Markers is added to mapbox with super delay

I am using map box in my android application. After initializing map box I want to add marker when on longClick on map box so in order according official site I added markerview dependency to application gradle:
dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v7:0.2.0'
}
And then I implements MapboxMap.OnMapLongClickListener and override onMapLongClick.
When mapview is ready I enable enableLocationComponent and create markerViewManager and set map long click listener.
mapView.getMapAsync(mapboxMap -> {
this.mapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
createCustomAnimationView();
moveTo(home_longitude, home_latitude, home_zoom);
enableLocationComponent();
markerViewManager = new MarkerViewManager(mapView, mapboxMap);
mapboxMap.addOnMapLongClickListener(this);
createCustomAnimationView();
});
});
Finally in onMapLongClick overrided method I make a imageview and add to markerViewManager.
#Override
public boolean onMapLongClick(#NonNull LatLng point) {
ImageView imageView = new ImageView(requireContext());
imageView.setLayoutParams(new RelativeLayout.LayoutParams(
(int) Measurement.convertDpToPixel(32, requireContext()),
(int) Measurement.convertDpToPixel(32, requireContext())));
imageView.setImageResource(R.drawable.location_ic);
MarkerView markerView = new MarkerView(new LatLng(point.getLatitude(), point.getLongitude()), imageView);
markerViewManager.addMarker(markerView);
return false;
}
When I run application and do long click on screen:
First problem: location_ic appear on the top and left of the screen and after a second or more, icon placed in right place
Other problem:
When I move map, those markers stay fixed and not moved with map but after a second or more then placed in right place.
I hope I had explained clearly but if you are not understanding I uploaded a small video !!!
My video
after a few days and googleing, I finally decided to use SymbolManager to add marker on mapbox:
just add :
dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.5.0'
}
to app gradle and then Initialize the plugin on onMapReady like below:
symbolManager = new SymbolManager(mapView, mapboxMap,style);
symbolManager.setIconAllowOverlap(true);
symbolManager.setTextAllowOverlap(true);
and use :
symbolManager.create(new SymbolOptions()
.withLatLng(point)
.withIconImage(IMAGE_MARKER_DEFAULT));
for helping look this page and this.
I hope it can be helpful.
I'm currently working with markers in mapbox too. But they are referred as "Symbols" in the latest versions.
To use them add the mapbox android sdk dependency to your project (tutorial from mapbox here ) and follow the other tutorial to use the symbol layer ( link here ).
If you have all your markers as a GeoJSON file, you can also add to a custom map that you would style on the mapbox website and then use in your app. ( other informations here )
I hope this can help you, this is my first attempt to answer at someone.

Polyline with infowindow in android app

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...

google map v2 issue with uft8 string for title in android

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" + "سلام");

Set a marker icon in Google Maps API

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));

Categories

Resources