【问题标题】:Flutter google map custom marker with gesture detector带有手势检测器的颤振谷歌地图自定义标记
【发布时间】:2021-11-21 02:58:56
【问题描述】:

现在我正在使用 google_maps_flutter 构建我的地图,但它在 Marker 中只有 onTap 功能,我该如何实现其他手势,如长按或点击等。

      Marker(
        markerId: MarkerId('1'),
        position: LatLng(25.032970, 121.565415),
        icon: await getMarkerIcon("imageUrl", Size(120.0, 120.0)),
        consumeTapEvents: true,
        onTap: () {
          print('onPress');
        },
        onLongPress?
      ),

【问题讨论】:

    标签: flutter google-maps


    【解决方案1】:
    BitmapDescriptor customIcon;
    
    // make sure to initialize before map loading
    BitmapDescriptor.fromAssetImage(ImageConfiguration(size: Size(12, 12)),
            'assets/images/car-icon.png')
        .then((d) {
      customIcon = d;
    });
    
    final nearbyCarsLocation = [
      LatLng(24.9286825, 67.0403249),
      LatLng(24.985577, 67.0661056), //24.9294892,67.0391903,18.73z
    ];
    
    void _getNearByCars() {
    
      for (var i = 0; i < nearbyCarsLocation.length; i++) {
        var now = new DateTime.now().millisecondsSinceEpoch;
        _markers.add(Marker(
          markerId: MarkerId(nearbyCarsLocation[i].toString() + now.toString()),
          position: nearbyCarsLocation[i],
          // infoWindow: InfoWindow(title: address, snippet: "go here"),
          icon: customIcon ));
      }
      notifyListeners();
    }
    

    希望这将有助于获得自定义附近的地区

    【讨论】:

    • 我不是在问如何制作自定义图标,而是如何为图标添加手势检测。
    猜你喜欢
    • 1970-01-01
    • 2020-01-13
    • 2016-09-20
    • 2019-06-30
    • 2021-08-07
    • 1970-01-01
    • 2013-05-20
    • 2015-01-28
    • 1970-01-01
    相关资源
    最近更新 更多