扑地图上的错误地图后发送短信

时间:2018-10-07 08:04:32

标签: flutter android-mapview

我在关闭地图视图后尝试发送短信。目前,我找到的唯一解决方案是在完成拖动新位置后发送短信。但它会在替换标记后一直发送短信...我只希望最后一个位置发送完一条短信。我试图在id == 1中推送(onAnnotationDragEnd.listen)以仅在地图关闭时激活该功能,但仅在关闭应用程序一次后才能起作用。它需要再次开放才能工作...要明确地说,我只是搜索如何启动mapview->拖动新位置->关闭地图视图->发送短信到最后一个位置。

这是插件:https://pub.dartlang.org/packages/map_view

这是函数

showMap() {

mapView.show(
    new MapOptions(
        mapViewType: MapViewType.hybrid,
        showUserLocation: true,
        initialCameraPosition: new CameraPosition(
            new Location(lathome,longhome),18.0),
        title: "change location"),
    toolbarActions: [new ToolbarAction("close", 1)]);
StreamSubscription sub = mapView.onMapReady.listen((_) {


  mapView.addMarker(
      new Marker("4", "Home",lathome,longhome,draggable: true, //
        color:Colors.orangeAccent, markerIcon: new MarkerIcon(
          "assets/home_tag_orange.png", //Asset to be used as icon
          width: 130.0, //New width for the asset
          height: 130.0, // New height for the asset
        ),));
  mapView.onAnnotationDragEnd.listen((markerMap) {
    var marker = markerMap.keys.last;
    var location = markerMap[marker]; // The updated position of the marker.
    print("Annotation ${marker.id} moved to ${location.latitude} , ${location
        .longitude}");
    new SmsSender().sendSms(new SmsMessage(phonenumber,'${location.latitude.toStringAsFixed(6)}",${location.longitude.toStringAsFixed(6)}'));
  });


  mapView.zoomToFit(padding: 500);
});
sub = mapView.onTouchAnnotation
    .listen((annotation) => print("annotation ${annotation.id} tapped"));
compositeSubscription.add(sub);

sub = mapView.onMapTapped
    .listen((location) => print("Touched location $location"));
compositeSubscription.add(sub);
sub = mapView.onCameraChanged.listen((cameraPosition) =>
    this.setState(() => this.cameraPosition = cameraPosition));
compositeSubscription.add(sub);

sub = mapView.onToolbarAction.listen((id) {
  print("Toolbar button id = $id");
  if (id == 1) {


    _handleDismiss();
  }
});
compositeSubscription.add(sub);
sub = mapView.onInfoWindowTapped.listen((marker) {
  print("Info Window Tapped for ${marker.title}");
});
compositeSubscription.add(sub);
 } 

0 个答案:

没有答案