Untitled

mail@pastecode.io avatar
unknown
dart
2 months ago
1.6 kB
4
Indexable
Never
import 'package:flutter/material.dart';
import 'package:yandex_mapkit/yandex_mapkit.dart';

class MyMapPage extends StatefulWidget {
  @override
  _MyMapPageState createState() => _MyMapPageState();
}

class _MyMapPageState extends State<MyMapPage> {
  late YandexMapController _mapController;
  late MapObjectId mapObjectId;

  @override
  void initState() {
    super.initState();
    mapObjectId = MapObjectId('map_object_id');
  }

  void _onMapCreated(YandexMapController controller) {
    _mapController = controller;

    // Dinleyici ekle
    _mapController.addCameraListener(_cameraListener);
    _mapController.addUserLocationListener(_userLocationListener);
  }

  // Örnek kamera hareketi dinleyicisi
  void _cameraListener(CameraUpdateReason reason, bool finished) {
    print('Camera update reason: $reason, finished: $finished');
  }

  // Örnek kullanıcı konumu dinleyicisi
  void _userLocationListener(UserLocationView view) {
    print('User location updated: ${view.target.latitude}, ${view.target.longitude}');
  }

  @override
  void dispose() {
    // Dinleyicileri kaldır
    _mapController.removeCameraListener(_cameraListener);
    _mapController.removeUserLocationListener(_userLocationListener);

    // MapController'i dispose et
    _mapController.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Yandex Map Example'),
      ),
      body: YandexMap(
        onMapCreated: _onMapCreated,
      ),
    );
  }
}

void main() => runApp(MaterialApp(
  home: MyMapPage(),
));
Leave a Comment