Flutter Google Maps插件的自定义标记

Dmi*_*lin 7 plugins google-maps flutter

有没有办法在地图上使用官方Flutter Google Maps插件显示自定义标记?根据文档找不到任何方法。

Saa*_*med 15

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();
}
Run Code Online (Sandbox Code Playgroud)

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


Rya*_*n R 7

BitmapDescriptor.fromAsset弃用

使用BitmapDescriptor.fromAssetImage来代替。

在选择合适的资产时,它尊重设备 DPI。请参阅声明分辨率感知图像资产


小智 7

算法 asi https://www.youtube.com/watch?v=ajuo0HjN3lY&t=905s

BitmapDescriptor icon;


@override
  void initState() {
    getIcons();
    super.initState();
  }


// Cargar imagen del Marker
  getIcons() async {
    var icon = await BitmapDescriptor.fromAssetImage(
        ImageConfiguration(devicePixelRatio: 3.2),
        "assets/images/markeruser.png");
    setState(() {
      this.icon = icon;
    });
  }


// Crear Marker
  createMarkers() {
    markers.add(
      Marker(
        markerId: MarkerId("MarkerCurrent"),
        position: currentLocation,
        icon: icon,
        infoWindow: InfoWindow(
            title: "Mi Ubicacion",
            snippet:
                "Lat ${currentLocation.latitude} - Lng ${currentLocation.longitude}"),
        draggable: true,
        onDragEnd: onDragEnd,
      ),
    );
  }

Run Code Online (Sandbox Code Playgroud)


Fra*_*Jr. 5

我正在使用:

controller.addMarker(MarkerOptions(
  icon: BitmapDescriptor.fromAsset("images/restaurant.png"),
  position: LatLng(40.017870, -105.278350),
));
Run Code Online (Sandbox Code Playgroud)

它可以在Android上正常运行,但不能在iOS上运行。

  • 有没有控制图标大小的选项? (3认同)
  • 我们不能只使用小部件吗:-| (3认同)
  • @Daniel.V 从技术上讲,您应该能够根据资产大小更改大小,但目前(至少对我而言)它不适用于 Android。描述符实现并未根据设备分辨率确定资产的正确路径。此外,当前的 GMaps 插件更多的是用于“hello wrold”演示而不是完整的应用程序。有很多工作要做。 (2认同)