3
2

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 3 years have passed since last update.

[Android]Google Map でピン立てる

Last updated at Posted at 2020-04-17

Google Map上で長押しからピンを立てる

以下の手順となります。
・長押しのイベントを取得
・Google Mapからピン情報を取得
・マーカー立てる

長押しのイベントを取得

GoogleMap.OnMapLongClickListener を使いたいクラスから extends する

class MapsActivity : AppCompatActivity(), GoogleMap.OnMapLongClickListener {
mMap.setOnMapLongClickListener(this)

Google Mapからピン情報を取得

override fun onMapLongClick(point: LatLng) {

overrideメソットからもらった point(LatLng)からマーカー作る

var marker = MarkerOptions().position(point).title("目的地")

マーカー立てる

private lateinit var mMap: GoogleMap
mMap!!.addMarker(marker)
marker_2.png

Screenshot_20200417-165102.png

3
2
0

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?