颤振图像未显示在Google标记上 [英] Flutter image not showing on google marker

查看:42
本文介绍了颤振图像未显示在Google标记上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在显示图像而不是正常标记,但不知道为什么未显示,我在其他地图页面上执行相同的操作,其工作方式-_-表示我在此处执行的操作相同它在此页面上显示简单的红色标记,在另一页上我可以看到我的图像标记.

I am showing an image instead of the normal marker but don't know why it's not showing, I am doing same way on other map page and its working -_- mean the same way I am doing as I am doing here its showing simple red marker on this page and another page I can see my image marker.

这是问题所在的我的页面代码

This is my page code where the issue is

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
      ),
    );
  }
}

这是图像在标记上显示的页面

And this is the page where image is showing on 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))

    );
  }

我有仔细检查的代码,但没有收到我做错的问题,为什么它仅在zzzz的一页上起作用

I have double-check code but don't get issue what I am doing wrong why it's working on one page only zzzz

推荐答案

您可以使用 BitmapDescriptor.fromAsset

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
  );

我希望这对您有用

这篇关于颤振图像未显示在Google标记上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆