Android 上的谷歌地图无法放大和缩小
当我设置触摸侦听器以获取触摸位置经纬度时,当我从代码中删除触摸侦听器时,放大和缩小不起作用。那么如何实现谷歌地图的放大和缩小以及长时间触摸位置呢?
我的代码如下
mapView = (MapView) findViewById(R.id.map);
mapView.setBuiltInZoomControls(true);
mapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("!!!!!","*****");
//---when user lifts his finger---
if (event.getAction() == MotionEvent.ACTION_UP) {
Projection p2 = mapView.getProjection();
GeoPoint geoPoint = p2.fromPixels((int) event.getX(), (int)event.getY());
int latitude = geoPoint.getLatitudeE6();
int longitude = geoPoint.getLongitudeE6();
String aString = Integer.toString(latitude);
String aString2 = Integer.toString(longitude);
Log.i("latitude,longitude",aString+",,"+aString2);
if((latitude < -34.538238) && (latitude > -34.672182))
{
if((longitude < -58.347702) && (longitude > -58.528976))
{
Log.i("lat,long",aString+",,"+aString2);
}
else
{
Log.i("out of region",aString+",,"+aString2);
}}
Log.i("@@@@@!!!!!","*****");
}
return true;
}
});
When I set on touch listener for getting touch location lat long then me zoom in and out is not working its working when I remove on touch listener from my code. So how to achieve to work zoom in and out in Google map and get touch location lat long?
My code is below
mapView = (MapView) findViewById(R.id.map);
mapView.setBuiltInZoomControls(true);
mapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("!!!!!","*****");
//---when user lifts his finger---
if (event.getAction() == MotionEvent.ACTION_UP) {
Projection p2 = mapView.getProjection();
GeoPoint geoPoint = p2.fromPixels((int) event.getX(), (int)event.getY());
int latitude = geoPoint.getLatitudeE6();
int longitude = geoPoint.getLongitudeE6();
String aString = Integer.toString(latitude);
String aString2 = Integer.toString(longitude);
Log.i("latitude,longitude",aString+",,"+aString2);
if((latitude < -34.538238) && (latitude > -34.672182))
{
if((longitude < -58.347702) && (longitude > -58.528976))
{
Log.i("lat,long",aString+",,"+aString2);
}
else
{
Log.i("out of region",aString+",,"+aString2);
}}
Log.i("@@@@@!!!!!","*****");
}
return true;
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您
setOnTouchListener
时,您的setBuiltInZoomControls(true)
将不起作用。您可以通过命令
displayZoomControls(true)
显示缩放按钮。您的地图不会缩放,也不会通过触摸或多点触摸移动,但您可以通过单击缩放按钮来缩放地图。另一种方法是当不需要处理触摸但需要缩放地图时,通过
mapView.setOnTouchListener(null)
关闭监听器,并通过setBuiltInZoomControls(true)
缩放地图。当您需要处理触摸时,您可以设置侦听器mapView.setOnTouchListener(new OnTouchLister(...))
但通过触摸进行缩放的机会就会丢失。当不需要触摸时,执行mapView.setOnTouchListener(null)
并再次执行setBuiltInZoomControls(true)
来缩放地图。When you
setOnTouchListener
yoursetBuiltInZoomControls(true)
will not work.You may show zoom button by command
displayZoomControls(true)
. Your map will not zoom and will not move by touch or multitouch but you will can zooming map by clicking to the zoom button.The other way is to shut off listener by
mapView.setOnTouchListener(null)
and zooming map bysetBuiltInZoomControls(true)
when you don't need processing touch but need to zoom map. In the moment when you need to process touch you set listenermapView.setOnTouchListener(new OnTouchLister(...))
but opportunity zooming by touch is lost. When touch isn't needed domapView.setOnTouchListener(null)
and againsetBuiltInZoomControls(true)
to zoom map.试试这个。应该能够获得缩放控件和您之前所做的 GeoPoint 内容。
返回 false 应该会给你缩放控件。该方法应该位于 Overlay 的子类中。在下面的代码中,“Touchy”类继承自 Overlay。
Try this. Should be able to get the zoom controls and the GeoPoint stuff you were doing earlier.
Returning false should give you the zoom controls. The method should be in a subclass of Overlay. In the code below, the class "Touchy" inherits from Overlay.