Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振图像未显示在google marker上_Flutter_Dart - Fatal编程技术网

Flutter 颤振图像未显示在google marker上

Flutter 颤振图像未显示在google marker上,flutter,dart,Flutter,Dart,我正在显示一个图像,而不是普通的标记,但不知道为什么它没有显示,我在其他地图页面上的操作方式和它的工作方式相同-意思是我在这里的操作方式与我在这一页面上的操作方式相同,它在这一页面上显示简单的红色标记,我可以看到我的图像标记 这是问题所在的页面代码 class _TripRouteScreenState extends State<TripRouteScreen> { var start_currentPostion; var end_currentPostion; Bi

我正在显示一个图像,而不是普通的标记,但不知道为什么它没有显示,我在其他地图页面上的操作方式和它的工作方式相同-意思是我在这里的操作方式与我在这一页面上的操作方式相同,它在这一页面上显示简单的红色标记,我可以看到我的图像标记

这是问题所在的页面代码

class _TripRouteScreenState extends State<TripRouteScreen> {
  var start_currentPostion;
  var end_currentPostion;
  BitmapDescriptor pinLocationIcon;

  Map<MarkerId, Marker> setmarkers = {};
  List listMarkerIds = List(); // For store data of your markers

  @override
  void initState() {
    super.initState();
    setCustomMapPin();
    working();
  }

  void setCustomMapPin() async {
    pinLocationIcon = await BitmapDescriptor.fromAssetImage(
        ImageConfiguration(devicePixelRatio: 2.5), 'images/pin.png');
  }

  working() {
    double start_latitude = widget.data['start']['lat'].toDouble();
    double start_longitude = widget.data['start']['lon'].toDouble();

    double end_latitude = widget.data['end']['lat'].toDouble();
    double end_longitude = widget.data['end']['lon'].toDouble();

    start_currentPostion = LatLng(start_latitude, start_longitude);
    end_currentPostion = LatLng(end_latitude, end_longitude);

    setState(() {
      MarkerId markerId1 = MarkerId("1");
      MarkerId markerId2 = MarkerId("2");

      listMarkerIds.add(markerId1);
      listMarkerIds.add(markerId2);

      Marker marker1 = Marker(
        markerId: markerId1,
        position: LatLng(start_latitude, start_longitude),
        icon: pinLocationIcon,
      );

      Marker marker2 = Marker(
        markerId: markerId2,
        position: LatLng(end_latitude, end_longitude),
        icon: pinLocationIcon, // you can change the color of marker
      );

      setmarkers[markerId1] =
          marker1; // I Just added here markers on the basis of marker id
      setmarkers[markerId2] = marker2;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          leading: GestureDetector(
              onTap: () {
                Navigator.pop(context);
              },
              child: Icon(Icons.arrow_back)),
          centerTitle: true,
          flexibleSpace: Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('images/nav.jpg'),
                fit: BoxFit.cover,
              ),
            ),
          ),
          backgroundColor: Colors.transparent,
          title: Text(
            'Route Location',
            style: TextStyle(fontFamily: 'UbuntuBold'),
          ),
          actions: [
            Padding(
              padding: const EdgeInsets.only(right: 15),
              child: Icon(
                Icons.notifications_none,
                size: 33,
              ),
            )
          ]),
      body: GoogleMap(
        mapType: MapType.normal,
        initialCameraPosition: CameraPosition(
          target: start_currentPostion,
          zoom: 15,
        ),
        markers: Set.of(setmarkers.values), // YOUR MARKS IN MAP
      ),
    );
  }
}
class\u TripRouteScreenState扩展状态{
var启动\当前位置;
var end_CurrentPosition;
位图描述符pinLocationIcon;
映射集标记={};
List listMarkerIds=List();//用于存储标记的数据
@凌驾
void initState(){
super.initState();
setCustomMapPin();
工作();
}
void setCustomMapPin()异步{
pinLocationIcon=等待BitmapDescriptor.fromAssetImage(
ImageConfiguration(devicePixelRatio:2.5),“images/pin.png”);
}
工作(){
双开始纬度=widget.data['start']['lat'].toDouble();
双起点经度=widget.data['start']['lon'].toDouble();
double end_latitude=widget.data['end']['lat'].toDouble();
双端经度=widget.data['end']['lon'].toDouble();
起始位置=纬度(起始纬度,起始经度);
end_CurrentPosition=纬度(end_纬度,end_经度);
设置状态(){
MarkerId markerId1=MarkerId(“1”);
MarkerId markerId2=MarkerId(“2”);
listMarkerIds.add(markerId1);
listMarkerIds.add(markerId2);
标记器1=标记器(
markerId:markerId1,
位置:LatLng(起始纬度,起始经度),
图标:pinLocationIcon,
);
Marker marker2=标记器(
markerId:markerId2,
位置:LatLng(纬度终点,经度终点),
icon:pinLocationIcon,//您可以更改标记的颜色
);
设置标记[markerId1]=
marker1;//我刚刚在这里添加了基于标记id的标记
setmarkers[markerId2]=marker2;
});
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
引导:手势检测器(
onTap:(){
Navigator.pop(上下文);
},
子:图标(图标。箭头返回)),
标题:对,
flexibleSpace:容器(
装饰:盒子装饰(
图像:装饰图像(
图像:AssetImage('images/nav.jpg'),
适合:BoxFit.cover,
),
),
),
背景颜色:颜色。透明,
标题:正文(
“路线位置”,
样式:TextStyle(fontFamily:“UbuntuBold”),
),
行动:[
填充物(
填充:仅限常量边集(右:15),
子:图标(
Icons.notices\u无,
尺码:33,
),
)
]),
正文:谷歌地图(
mapType:mapType.normal,
initialCameraPosition:CameraPosition(
目标:启动当前位置,
缩放:15,
),
markers:Set.of(setmarkers.values),//您在地图中的标记
),
);
}
}
这是在marker上显示图像的页面

class _MapScreenState extends State<MapScreen> {
  Completer<GoogleMapController> _controller = Completer();
  Set<Marker> _markers;
  bool loading = true;
  var currentPostion;
  Map<MarkerId, Marker> markers = <MarkerId, Marker>{}; // CLASS MEMBER, MAP OF MARKS
  BitmapDescriptor pinLocationIcon;


  @override
  void initState() {
    super.initState();
    _markers = Set<Marker>();

    setCustomMapPin();
    getImi();
  }
  void setCustomMapPin() async {
    pinLocationIcon = await BitmapDescriptor.fromAssetImage(
        ImageConfiguration(devicePixelRatio: 2.5),
        'images/pin.png');
  }

  getImi() async {
    final storage = new FlutterSecureStorage();

    String imi = await storage.read(key: "imei");
    print('showimi');
    print(imi);

    var map = new Map<String, dynamic>();

    var url =
        'http://api.igiinsurance.com.pk:8888/drive_api/location.php?imei=${imi}';
    print(url);
    http.Response res = await http.get(
      url,
      headers: <String, String>{
        'token': 'c66026133e80d4960f0a5b7d418a4d08'
      },
    );
    var data = json.decode(res.body.toString());
    print(data);

    if (data['status'].toString() == "success") {
      print(data["data"]["location"]["lon"]);
      print(data["data"]["location"]["gc"]["rd"]);
      print(data["data"]["location"]["gc"]["sb"]);

      var tit = data["data"]["location"]["gc"]["rd"];
      var snip = data["data"]["location"]["gc"]["sb"];

      print(data['lon']);
      print(data['lat']);
      double latitude = data['lat'].toDouble();
      double longitude = data['lon'].toDouble();

      print(longitude);


      currentPostion = LatLng(latitude, longitude);
      print(currentPostion);

      final Map<String, Marker> _markers = {};

      setState(() {
        final MarkerId markerId = MarkerId('1');

        // creating a new MARKER
        final Marker marker = Marker(
          markerId: markerId,
          icon: pinLocationIcon,

          position: currentPostion,
          infoWindow: InfoWindow(title: tit, snippet: snip),

        );

        setState(() {
          // adding a new marker to map
          markers[markerId] = marker;
        });
        loading = false;
      }
      );
    }
  }


  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
          leading: GestureDetector(
              onTap: () {
                Navigator.pop(context);
              }, child: Icon(Icons.arrow_back)),
          centerTitle: true,
          flexibleSpace: Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('images/nav.jpg'),
                fit: BoxFit.cover,
              ),
            ),
          ),
          backgroundColor: Colors.transparent,
          title: Text(
            'My Car Location', style: TextStyle(fontFamily: 'UbuntuBold'),),
          actions: [
            Padding(
              padding: const EdgeInsets.only(right: 15),
              child: Icon(
                Icons.notifications_none,
                size: 33,
              ),
            )
          ]),
      body: loading == false ? GoogleMap(
        mapType: MapType.normal,
        initialCameraPosition: CameraPosition(
          target: loading == false ? currentPostion : LatLng(1.0, 1.0),
          zoom: 18,
        ),
        markers: Set<Marker>.of(markers.values), // YOUR MARKS IN MAP

      ) :
        Center(
            child:  SpinKitWave(color: Color(0xff00abb5), type: SpinKitWaveType.center))

    );
  }
class\u映射屏幕状态扩展状态{
Completer _controller=Completer();
设置标记;
布尔加载=真;
无功电流位置;
映射标记={};//类成员,标记映射
位图描述符pinLocationIcon;
@凌驾
void initState(){
super.initState();
_markers=Set();
setCustomMapPin();
getImi();
}
void setCustomMapPin()异步{
pinLocationIcon=等待BitmapDescriptor.fromAssetImage(
图像配置(devicePixelRatio:2.5),
“images/pin.png”);
}
getImi()异步{
最终存储=新存储();
字符串imi=wait storage.read(键:“imei”);
印刷品(‘showimi’);
打印(imi);
var map=newmap();
变量url=
'http://api.igiinsurance.com.pk:8888/drive_api/location.php?imei=${imi}';
打印(url);
Response res=wait http.get(
网址,
标题:{
“令牌”:“c66026133e80d4960f0a5b7d418a4d08”
},
);
var data=json.decode(res.body.toString());
打印(数据);
如果(数据['status'].toString()=“成功”){
打印(数据[“数据”][“位置”][“长度]);
打印(数据[“数据”][“位置”][“gc”][“rd”]);
打印(数据[“数据”][“位置”][“gc”][“sb”]);
var tit=data[“data”][“location”][“gc”][“rd”];
var snip=data[“data”][“location”][“gc”][“sb”];
打印(数据['lon']);
打印(数据['lat']);
双纬度=数据['lat'].toDouble();
双经度=数据['lon'].toDouble();
打印(经度);
CurrentPosition=纬度、经度;
打印(当前位置);
最终地图_标记={};
设置状态(){
最终MarkerId MarkerId=MarkerId('1');
//创建新标记
最终标记=标记(
马克里德:马克里德,
图标:pinLocationIcon,
职位:当前职位,
infoWindow:infoWindow(标题:tit,片段:snip),
);
设置状态(){
//向地图添加新标记
markers[markerId]=标记器;
});
加载=假;
}
);
}
}
@凌驾
小部件构建(构建上下文){
归还新脚手架(
appBar:appBar(
引导:手势检测器(
onTap:(){
Navigator.pop(上下文);
},子:图标(Icons.arrow_back)),
标题:对,
flexibleSpace:容器(
装饰:盒子装饰(
图像:装饰图像(
图像:AssetImage('images/nav.jpg'),
适合:BoxFit.cover,
),
),
),
背景颜色:颜色。透明,
标题:正文(
“我的汽车位置”,样式:TextStyle(fontFamily:“UbuntuBold”),
Marker marker1 = Marker(
    markerId: markerId1,
    position: LatLng(start_latitude, start_longitude),
    icon: BitmapDescriptor.fromAsset("images/pin.png"),
  );


  Marker marker2 = Marker(
    markerId: markerId2,
    position: LatLng(end_latitude, end_longitude),
    icon: BitmapDescriptor.fromAsset("images/pin.png"),  // you can change the color of marker
  );