在Google地图上制作可点击的多边形(适用于Android) [英] Make clickable polygons on Google Maps (for Android)
本文介绍了在Google地图上制作可点击的多边形(适用于Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
setOnMapClickListener
。据我所知,这很幼稚。什么是替代方法?
解决方案
以下是我做到的方式。
< (新的LatLng(12.780712,77.770956),新的LatLng(12.912006,77.229738),新的LatLng()新的LatLng(12.780712,77.770956),$新的LatLng新的LatLng(12.912006,77.229738))
.strokeColor(0xFF00AA00)
.fillColor(0x2200FFFF)
.strokeWidth(2)
);
polygon.setClickable(true);
$ b getMap()。setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener(){
public void onPolygonClick(Polygon polygon){
mClusterManager = new ClusterManager< MyItem>(getApplicationContext (),getMap());
getMap()。setOnCameraChangeListener(mClusterManager);
getMap()。moveCamera(CameraUpdateFactory.newLatLngZoom(getMap()。getCameraPosition().get,getMap()。getCameraPosition ().zoom));
try {
readItems();
} catch(JSONException e){
Toast.makeText(getApplicationContext(),Problem阅读标记列表,Toast.LENGTH_LONG).show();
}
}
});
希望有所帮助。
I have continuous LatLngs of various areas in a city. Is there any way I can create clickable polygons with it. Once way to go about would be to
- Generate polygons with the available LatLngs.( I want to visually show the polygons on the map with color encoding)
- Set up
setOnMapClickListener
. - Do a point inside polygon test.
I understand that this is very naive. What are the alternative approaches?
解决方案
Here's how I did it.
Polygon polygon = getMap().addPolygon(new PolygonOptions()
.add(new LatLng(12.780712, 77.770956), new LatLng(12.912006, 77.229738), new LatLng(12.412006, 77.629738), new LatLng(12.912006, 77.229738))
.strokeColor(0xFF00AA00)
.fillColor(0x2200FFFF)
.strokeWidth(2)
);
polygon.setClickable(true);
getMap().setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
public void onPolygonClick(Polygon polygon) {
mClusterManager = new ClusterManager<MyItem>(getApplicationContext(), getMap());
getMap().setOnCameraChangeListener(mClusterManager);
getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(getMap().getCameraPosition().target, getMap().getCameraPosition().zoom));
try {
readItems();
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Problem reading list of markers.", Toast.LENGTH_LONG).show();
}
}
});
Hope that helps.
这篇关于在Google地图上制作可点击的多边形(适用于Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文