2

I am using Yandex's MapKit in my android application. The documentation is very lacking and not helpful at all. I did the basic set-up. Map is working fine. But I am having problems with:

  1. How to add marker on the map? I tried the code they suggested:
       val mapObjects = mapView.map.mapObjects.addCollection()
       val mark: PlacemarkMapObject = mapObjects.addPlacemark(Point(X, Y))
       mark.opacity = 0.5f
       mark.setIcon(ImageProvider.fromResource(requireContext(), R.drawable.ic_heart))
       mark.isDraggable = true

It is not working and marker is not showing on the map.

  1. But I would like to enable some other controls the map offers. Like zoom in and search. Take a look at the picture:

enter image description here

How can I add those controls on my mapView ? Any suggestions would be greatly appreciated.

Azizjon Kholmatov
  • 1,136
  • 1
  • 13
  • 26

3 Answers3

-2

You need to add them programatically or using interface builder (Don't know correct name in android studio) as a Custom View and then implement whatever logic you need. Yandex Map Kit doesn't provide any default implementation of it.

Maksim
  • 11
  • 1
  • 5
-2

if you add marker svg icon to Yandex map you do like this:

class AddMarkerActivity : AppCompatActivity() {
// change this locations
    private val endRoute = Point(41.275548, 69.204386) // 69.197425, 41.256773
    private val endRoute2 = Point(41.273366, 69.210980) // 69.197425, 41.256773
    private val endRoute3 = Point(41.282035, 69.213861) // 69.197425, 41.256773
    private val endRoute4 = Point(41.277995, 69.229924) // 69.197425, 41.256773

 private lateinit var mapView: MapView

override fun onCreate(savedInstanceState: Bundle?) {
        MapKitFactory.setApiKey("Your_Yandex_API_Key")
        MapKitFactory.initialize(this)
        DirectionsFactory.initialize(this)

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_draw_route)


        mapView = findViewById(R.id.yandex_map)

        mapView.setOnClickListener {
            toast("${(it as MapView).focusPoint.x} , : , ${it.focusPoint.y}")
        }

        userLocation.setTapListener {
            Log.d("TTT", "location: ${it.latitude} ${it.longitude}")
        }
       drawLocationMark(endRoute, mapView)
       drawLocationMark(endRoute2, mapView)
       drawLocationMark(endRoute3, mapView)
       drawLocationMark(endRoute4, mapView)

    }

   private fun drawMyLocationMark(point: Point, mapview: MapView) {
      val view = View(this).apply { 
     background = getDrawable(R.drawable.ic_baseline_location_on_24)
     }

     mapview.map.mapObjects.addPlacemark(point, ViewProvider(view))
    }
}
  • private fun drawMyLocationMark(point: Point, mapview: MapView) { val view = View(this).apply { background = getDrawable(R.drawable.ic_baseline_location_on_24) } mapview.map.mapObjects.addPlacemark( point, ViewProvider(view) ) } – Ulugbek Yusupov Mar 31 '22 at 10:26
  • Please share any relevant code [instead of a screenshot](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) by editing your Question. Fewer people are likely to reproduce your issue without having your code in a copyable form. – tjheslin1 Mar 31 '22 at 10:47
-2

activity layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.yandex.mapkit.mapview.MapView
        android:id="@+id/yandex_map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</androidx.constraintlayout.widget.ConstraintLayout>