2

I want to detect map position change (same as map camera change) in Yandex maps. Google maps API provide this opportunity via OnCameraChangeListener(), but I couldn't find the appropriate one for Yandex one.

SO:Which is the appropriate function of Google's OnCameraChangeListener in Yandex maps?

Thanks in advance.

Hayk Nahapetyan
  • 4,452
  • 8
  • 42
  • 61

2 Answers2

0

I know the answer is too so late , but maybe help someone :

class GeofenceActivity : ComponentActivity() , CameraListener {
    private lateinit var mapViewYandex: com.yandex.mapkit.mapview.MapView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        SetupMapInitializing(this)
        mapViewYandex.map.addCameraListener(this)


    }
private fun SetupMapInitializing(cx : Context){
    try {
        MapKitFactory.setApiKey("your-key")
        MapKitFactory.initialize(cx)
        I18nManagerFactory.setLocale(Locale.getDefault().language)
    } catch(e : IOException){
        e.printStackTrace()
    }
}

    override fun onCameraPositionChanged(
        p0: Map,
        p1: CameraPosition,
        p2: CameraUpdateReason,
        p3: Boolean
    ) {
        Log.w(
            "Yandex",
            p1.target.latitude.toString() + " , " +
                    p1.target.longitude.toString()
        )
    }
}
u0j
  • 116
  • 1
  • 2
0

You need top add an event handler for the map with the title of boundschange

Here is some simplae sample code:

<script>
        var myMap;
        
        ymaps.ready(init);

        function init () {
            
            myMap = new ymaps.Map('map', {
                center: [55.76, 37.64], // Moscow
                zoom: 10
            });

            //add an event handler for detecting any change to the boudnaries of the map
            myMap.events.add('boundschange', onBoundsChange);

            //a callback function to do something with the new boundaries
            function onBoundsChange(e){
                console.log(e.originalEvent.newBounds);
            }
        }
    </script>  

And the most basic HTML:

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Detecting boundary changes of a Yandex Map</title>
    
    <script src="https://api-maps.yandex.ru/2.1/?lang=en_RU&amp;apikey=<your API-key>" type="text/javascript"></script>
    <style>
        body, html {
            padding: 0;
            margin: 0;
            width: 100%;
            height: 100%;
        }
        #map {
            width: 100%;
            height: 90%;
        }
    </style> 
</head>
<body>
    <div id="map"></div>
</body>
</html>
Orbiting Eden
  • 1,522
  • 13
  • 16