[英]How to translate Canvas Points to Map Coordinates
I am drawing a shape on the map. 我正在地图上绘制形状。 Actually, I am using a View on a map to draw a shape.
实际上,我在地图上使用“视图”绘制形状。 I brought this View to front on some button click.
通过单击某些按钮,我将此视图置于最前面。 So, map is residing back to this View.
因此,地图位于该视图的后面。 I am able to draw a shape on the View using canvas.
我可以使用画布在视图上绘制形状。 Now, I want these points to be converted to Map coordinates.
现在,我希望将这些点转换为地图坐标。
See this image, 看到这张图片,
It seems that drawing is done on the map. 似乎在地图上绘制了。 But the drawing is done on a transparent View.
但是绘图是在透明View上完成的。 From these canvas Points, I want to translate to Map Coordinates.
从这些画布点,我想转换为地图坐标。
I don't know how to achieve this. 我不知道该如何实现。 Please suggest me any idea of how to do this.
请建议我有关如何执行此操作的任何想法。
my code, 我的代码,
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
path = new Path();
float upX;
float upY;
Log.d("", "OnTouch");
switch (action) {
case MotionEvent.ACTION_DOWN:
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
downx = event.getX();
downy = event.getY();
eventX = downx;
eventY = downy;
Log.d("", "startx" + eventX);
break;
case MotionEvent.ACTION_MOVE:
upx = event.getX();
upy = event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
drawable.invalidate();
downx = upx;
downy = upy;
break;
case MotionEvent.ACTION_UP:
upX = event.getX();
upY = event.getY();
Log.d("", "Action Up");
Log.d("", "endx" + upX);
canvas.drawLine(eventX, eventY, upX, upY, paint);
drawable.invalidate();
return true;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
return true;
}
I want to perform some functinality in this area drawn by getting the N,E,W,S coordinates(map coordinates) from the drawing on the view. 我想通过从视图上的图形获取N,E,W,S坐标(地图坐标)在此绘制的区域中执行一些功能。 In which way I can modify my code.
我可以用哪种方式修改我的代码。 Please suggest me.
请给我建议。
Please provide me any links if possible. 如果可能的话,请提供我任何链接。 Any help is appreciated!!
任何帮助表示赞赏!
您想要的是Projection https://developers.google.com/maps/documentation/android/v1/reference/com/google/android/maps/Projection ,请问为什么在onTouch中在Canvas上绘制任何内容?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.