【问题标题】:Add marker on google map on touched location in Android在Android中触摸位置的谷歌地图上添加标记
【发布时间】:2011-10-13 09:23:56
【问题描述】:

谁能帮我完成以下任务:

我想在 android 的谷歌地图中添加一个标记。

功能必须是这样,必须显示一个弹出窗口才能将触摸的位置添加为标记。

我指的是下面的教程,他们通过硬编码添加标记。

http://developer.android.com/resources/tutorials/views/hello-mapview.html

我希望在地图上使用 onclck 来完成。

【问题讨论】:

标签: android google-maps google-maps-markers


【解决方案1】:

我使用了 Google Maps API v2,解决方法如下:

googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {

    @Override
    public void onMapClick(LatLng point) {          
        MarkerOptions marker = new MarkerOptions()
            .position(new LatLng(point.latitude, point.longitude))
            .title("New Marker");           
        googleMap.addMarker(marker);            
        System.out.println(point.latitude + "---" + point.longitude);   
    }
});

【讨论】:

    【解决方案2】:

    MapView 中,您必须使用onTouch 而不是onClick。此事件触发的motionEvent 具有触摸坐标,因此使用MapView 中的getProjection() 方法,您可以将触摸坐标转换为纬度和经度,以将Overlay (Marker) 放在地图上。

    【讨论】:

      猜你喜欢
      • 2011-01-11
      • 2018-07-31
      • 2013-06-13
      • 2017-10-08
      • 2017-12-25
      • 2016-03-16
      • 2018-11-13
      相关资源
      最近更新 更多