GoogleMapActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import android.app.Activity; import android.os.Bundle; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class GoogleMapActivity extends Activity { private GoogleMap mMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)) .getMap(); if (mMap != null) { mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(29, -88), 0)); mMap.addMarker(new MarkerOptions().position( new LatLng(38.8895, -77.0352)).title( getString(R.string.in_washington_string))); mMap.addMarker(new MarkerOptions().position( new LatLng(19.13, -99.4)).title( getString(R.string.in_mexico_string))); } } } |
main.xml
1 2 3 4 5 6 |
<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:name="com.google.android.gms.maps.MapFragment" android:layout_width="match_parent" android:layout_height="match_parent" /> |