这是我的 MainActivity.java 代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fr_mgr = getFragmentManager();
MapFragment map_frag = (MapFragment) fr_mgr.findFragmentById(R.id.map);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
map = map_frag.getMap();
map.setMyLocationEnabled(true);
LatLng Bhopal = new LatLng(23.233243200000000000, 77.434339400000000000);
map.addMarker(new MarkerOptions()
.position(new LatLng(23.233243200000000000, 77.434339400000000000))
.title("Hello Bhopal")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
Polygon polygon = map.addPolygon(new PolygonOptions()
.add(new LatLng(23.226834, 77.355309),
new LatLng(23.214845, 77.42672),
new LatLng(23.187707, 77.388954),
new LatLng(23.200961, 77.31411)).strokeColor(Color.RED)
.fillColor(Color.parseColor("#51000000")).strokeWidth(2));
}
}
这是我的布局文件“activity_main.xml”:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>