本文介绍了方法文档OnTouch在油漆覆盖(GOOGLEMAPS)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我画一个覆盖在我的GOOGLEMAPS视图(闭合多边形,填充)。但现在我不知道该如何弹出一个敬酒的时候我就覆盖挖掘。最至极的例子,我发现工作,标志,看起来柠不同的到我的code。
主要活动:
公共类BOSLstItemDetail扩展MapActivity {
ArrayList的<&HashMap的LT;弦乐,对象>> boslst;
MapView类MapView类;
MapController地图控件;
GeoPoint的磷;
多边形多边形; @覆盖
保护布尔isRouteDisplayed(){
返回false;
} @覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.boslst_item_detail); 字符串的坐标[] = {48.098056,9.788611};
双纬度= Double.parseDouble(坐标[0]);
双经度= Double.parseDouble(坐标[1]); P =新的GeoPoint(
(INT)(LAT * 1E6)
(INT)(LNG * 1E6)); MapView类MapView类=(图形页面)findViewById(R.id.mapview);
地图控件= mapView.getController();
mapcontrol.animateTo(P);
mapcontrol.setZoom(10);
mapView.setBuiltInZoomControls(真); ArrayList的<&GeoPoint的GT;点=新的ArrayList<&GeoPoint的GT;();
尝试{
InputStream的koord = getAssets()开(gps.txt);
如果(koord!= NULL){
InputStreamReader中输入=新的InputStreamReader(koord);
的BufferedReader buffreader =新的BufferedReader(输入);
串线;
而((行= buffreader.readLine())!= NULL){
串[] point_t = line.split(,);
双Y = Double.parseDouble(point_t [0]);
双X = Double.parseDouble(point_t [1]);
points.add(新的GeoPoint((int)的(X * 1e6个电子),(INT)(γ* 1e6个电子)));
}
koord.close();
多边形=新的多边形(点);
}
}赶上(例外五){
Log.e(APP,失败,E);
} 调用MapView.getOverlays()清()。
。调用MapView.getOverlays()加(多边形);
mapView.invalidate();
}
}
Polygon.java
公共类多边形扩展覆盖{
ArrayList的<&GeoPoint的GT; geoPoints; 公共多边形(ArrayList的<&GeoPoint的GT;点){
geoPoints =分;
} @覆盖
公共无效画(油画画布,MapView类MapView类,布尔阴影){
//设置颜色和样式
涂料粉刷=新的油漆();
paint.setColor(Color.parseColor(#88ff0000));
paint.setAlpha(50);
paint.setStyle(Paint.Style.FILL_AND_STROKE); //创建路径和加分
路径path =新路径();
点firstPoint =新点();
MapView.getProjection()在toPixels(geoPoints.get(0),firstPoint)。
path.moveTo(firstPoint.x,firstPoint.y); 的for(int i = 1; I< geoPoints.size(); ++ I){
NextPoint公司点=新点();
MapView.getProjection()在toPixels(geoPoints.get(ⅰ),NextPoint公司)。
path.lineTo(nextPoint.x,nextPoint.y);
} //关闭多边形
path.lineTo(firstPoint.x,firstPoint.y);
path.setLastPoint(firstPoint.x,firstPoint.y);
canvas.drawPath(路径,油漆);
super.draw(画布,MapView类,阴影); }
}
gps.txt:
9.34669876098644,48.2405319213867
9.36384963989269,48.2296714782715
9.3639497756958,48.2259712219238
9.87827968597418,48.2786293029785
9.87261867523205,48.2822494506837
9.87254810333263,48.2859611511232
9.88368034362787,48.2898597717285
9.8835382461549,48.2972793579102
9.72781181335461,47.9827613830566
9.72225093841558,47.9826812744141
9.72232818603527,47.9789619445801
9.71129894256597,47.9750900268555
9.70574092864985,47.9750099182129
9.70557022094732,47.9824409484864
9.69992923736572,47.9860801696778
9.69436073303234,47.9860000610352
9.33546066284174,48.2403602600099
9.34669876098644,48.2405319213867
解决方案
如果您正在扩展覆盖,可以覆盖ONTAP方式:
保护布尔中的onTap(最终诠释指数)
{
OverlayItem项目= mOverlays.get(指数);
如果(项目!= NULL){
Toast.makeText(mContext,textToShow,Toast.LENGTH_SHORT).show();
}
//返回true,表示我们已经采取照顾它
返回true;
}
I paint a overlay on my googlemaps view (closed polygon, filled). But now I don't know how to pop up a toast when I tap on the overlay. The most examples wich I found work with marker and looks verry different to my code.
Main Activity:
public class BOSLstItemDetail extends MapActivity{
ArrayList<HashMap<String, Object>> boslst;
MapView mapView;
MapController mapcontrol;
GeoPoint p;
Polygon polygon;
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.boslst_item_detail);
String coordinates[] = {"48.098056", "9.788611"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
MapView mapView = (MapView) findViewById(R.id.mapview);
mapcontrol = mapView.getController();
mapcontrol.animateTo(p);
mapcontrol.setZoom(10);
mapView.setBuiltInZoomControls(true);
ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();
try{
InputStream koord = getAssets().open("gps.txt");
if (koord != null) {
InputStreamReader input = new InputStreamReader(koord);
BufferedReader buffreader = new BufferedReader(input);
String line;
while (( line = buffreader.readLine()) != null) {
String[] point_t = line.split(",");
double y = Double.parseDouble(point_t[0]);
double x = Double.parseDouble(point_t[1]);
points.add(new GeoPoint((int)(x*1e6), (int)(y*1e6)));
}
koord.close();
polygon = new Polygon(points);
}
}catch (Exception e) {
Log.e("APP","Failed", e);
}
mapView.getOverlays().clear();
mapView.getOverlays().add(polygon);
mapView.invalidate();
}
}
Polygon.java
public class Polygon extends Overlay {
ArrayList<GeoPoint> geoPoints;
public Polygon(ArrayList<GeoPoint> points){
geoPoints = points;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow){
//Set the color and style
Paint paint = new Paint();
paint.setColor(Color.parseColor("#88ff0000"));
paint.setAlpha(50);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
//Create path and add points
Path path = new Path();
Point firstPoint = new Point();
mapView.getProjection().toPixels(geoPoints.get(0), firstPoint);
path.moveTo(firstPoint.x, firstPoint.y);
for(int i = 1; i < geoPoints.size(); ++i){
Point nextPoint = new Point();
mapView.getProjection().toPixels(geoPoints.get(i), nextPoint);
path.lineTo(nextPoint.x, nextPoint.y);
}
//Close polygon
path.lineTo(firstPoint.x, firstPoint.y);
path.setLastPoint(firstPoint.x, firstPoint.y);
canvas.drawPath(path, paint);
super.draw(canvas, mapView, shadow);
}
}
gps.txt:
9.34669876098644,48.2405319213867
9.36384963989269,48.2296714782715
9.3639497756958,48.2259712219238
9.87827968597418,48.2786293029785
9.87261867523205,48.2822494506837
9.87254810333263,48.2859611511232
9.88368034362787,48.2898597717285
9.8835382461549,48.2972793579102
9.72781181335461,47.9827613830566
9.72225093841558,47.9826812744141
9.72232818603527,47.9789619445801
9.71129894256597,47.9750900268555
9.70574092864985,47.9750099182129
9.70557022094732,47.9824409484864
9.69992923736572,47.9860801696778
9.69436073303234,47.9860000610352
9.33546066284174,48.2403602600099
9.34669876098644,48.2405319213867
解决方案
If you're extending Overlay, you can override the OnTap method:
protected boolean onTap(final int index)
{
OverlayItem item = mOverlays.get(index);
if(item != null){
Toast.makeText(mContext, textToShow, Toast.LENGTH_SHORT).show();
}
//return true to indicate we've taken care of it
return true;
}
这篇关于方法文档OnTouch在油漆覆盖(GOOGLEMAPS)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!