3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

google_maps_flutterでMapにマーカーが立たない

Posted at

鹿児島で大学院に通っております、Flutter初心者です。
はじめてのqiitaの投稿なので間違っていたり、その他まずい部分があったりした場合はコメントしていただけると助かります。
今回GoogleMapのAPIを以下の記事を参考にしていた際に詰まった点についてまとめました。
Google公式Flutter用Google Mapsプラグインを一通り使ってみた

#詰まったところ
地図上にマーカーを表示させる際に


The method 'MarkerOptions' isn't defined for the class '_GmapState'.
Try correcting the name to the name of an existing method, or defining a method named 'MarkerOptions'.d

The method 'addMarker' isn't defined for the class 'GoogleMapController'.
Try correcting the name to the name of an existing method, or defining a method named 'addMarker'.

というエラーメッセージが、

#原因
dependencyにgoogle_maps_flutterを追加する際に

dev_dependencies:
  google_maps_flutter: ^0.5.10

「とりあえず新しいの入れとけ!」ってしたのが間違いでした、、、
google_maps_flutter公式サイトを見てみると、なるほどgoogle_maps_flutterの新しい方のバージョンにMarkerOptionsがないのか、、、

#解決方法

    setState(() {
      mapController = controller;
      Marker marker = Marker(
        markerId: MarkerId(''),
        position: LatLng(31.568945, 130.545083),//マーカーを立てる緯度経度
      );
      markers.add(marker);
    });

新しくMarkerというClassがありましたのでそれを使うらしいです。
markerIdはないと

The parameter 'markerId' is required.

とメッセージが出たので適当に仮置きしてます。

#結果
スクリーンショット 2019-05-05 16.34.25.png
無事にマーカーが立ちました〜

#参考
Google公式Flutter用Google Mapsプラグインを一通り使ってみた
google_maps_flutter公式サイト

3
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?