I implemented the Google maps API V2 on Android, I got the map to show and also the polygon to show using this code:
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);
}
}
On the Google map API V1 the onTap
method is used to interact with the polygon. My question is what's the best way to get onTap events in version2? I've read the Google docs and unless I missed it, I did not see anything on it.