我在 Android 上实现了 Google 地图 API V2,我得到了要显示的地图和要显示的多边形,使用以下代码:
public class MainActivity extends FragmentActivity {
Polygon polygon;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleMap googleMap;
googleMap = ((SupportMapFragment)(getSupportFragmentManager().findFragmentById(R.id.map))).getMap();
LatLng latLng = new LatLng(35.20418,-90.08342);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("My Spot")
.snippet("This is my spot!")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10));
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(status == ConnectionResult.SUCCESS) {
//Success! Do what you want
Log.i("service", "Google play available");
}
else{
Log.i("service", "No Google play available");
}
PolygonOptions rectOptions = new PolygonOptions()
.add(new LatLng(35.25010,-90.08342),
new LatLng(35.25010,-90.04175),
new LatLng(35.29177,-90.04175),
new LatLng(35.29177,-90.08342),
new LatLng(35.25010,-90.08342));
//Set the rectangle's stroke color to red
rectOptions.strokeColor(Color.BLUE);
//Set the rectangle's fill to blue
rectOptions.fillColor(Color.CYAN);
rectOptions.strokeWidth(2);
//Get back the mutable Polygon
polygon = googleMap.addPolygon(rectOptions);
}
}
在 Google 地图 API V1 中,该onTap
方法用于与多边形交互。我的问题是在 version2 中获取 onTap 事件的最佳方式是什么?我已经阅读了 Google 文档,除非我错过了它,否则我没有看到任何内容。