添加标记使用谷歌android系统中的地图触摸位置 [英] Add marker on touched location using google map in android

查看:154
本文介绍了添加标记使用谷歌android系统中的地图触摸位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何添加一个标记在地图上的特定位置?

我看到这个code,显示触摸位置的坐标。我想一个标记弹出,或在同一位置每次它被触摸显示。我该怎么做呢?

 公共布尔的onTouchEvent(MotionEvent事件,图形页面图形页面){
                如果(event.getAction()== 1){
                    的GeoPoint P = MapView.getProjection()在。fromPixels(
                        (int)的event.getX(),
                        (int)的event.getY());
                        Toast.makeText(getBaseContext(),
                            p.getLatitudeE6()/ 1E6 +,+
                            p.getLongitudeE6()/ 1E6,
                            Toast.LENGTH_SHORT).show();

                        mapView.invalidate();
                }
                返回false;
            }
 

解决方案

您要添加的 OverlayItem 。该谷歌MapView类教程展示了如何使用它

How do I add a marker on a particular location in the map?

I saw this code that shows the coordinates of the touched location. And I want a marker to pop or be shown in that same location everytime it is touched. How do I do this?

 public boolean onTouchEvent(MotionEvent event, MapView mapView) {   
                if (event.getAction() == 1) {                
                    GeoPoint p = mapView.getProjection().fromPixels(
                        (int) event.getX(),
                        (int) event.getY());
                        Toast.makeText(getBaseContext(), 
                            p.getLatitudeE6() / 1E6 + "," + 
                            p.getLongitudeE6() /1E6 , 
                            Toast.LENGTH_SHORT).show();

                        mapView.invalidate();
                }                            
                return false;
            }

解决方案

You want to add an OverlayItem. The Google Mapview tutorial shows how to use it.

这篇关于添加标记使用谷歌android系统中的地图触摸位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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