谷歌地圖API V2實現多邊形我實現了Android手機上的谷歌地圖API V2,我得到了地圖顯示,並且還多邊形來使用此代碼顯示:與Android中
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);
}
}
在谷歌地圖API V1的onTap
方法用於與多邊形進行交互。我的問題是在版本2中獲取onTap事件的最佳方式是什麼?我已閱讀Google文檔,除非我錯過了它,否則我沒有看到任何內容。
回答這個問題,讓我在正確的道路上:http://stackoverflow.com/questions/26017892/android-check-if-my-lat-lng-position-withing-a-given-面積 –