-
-
Save carlosjs23/15f8e393f9dff5ed1ac05baf66f41866 to your computer and use it in GitHub Desktop.
Android Google Maps V2 - MapView in XML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" > | |
<com.google.android.gms.maps.MapView android:id="@+id/map" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" /> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MapsFragment extends Fragment implements OnMapReadyCallback { | |
MapView mapView; | |
GoogleMap mMap; | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View v = inflater.inflate(R.layout.map_layout, container, false); | |
// Gets the MapView from the XML layout and creates it | |
mapView = (MapView) v.findViewById(R.id.mapview); | |
mapView.onCreate(savedInstanceState); | |
// Gets to GoogleMap from the MapView and does initialization stuff | |
mapView.getMapAsync(this); | |
MapsInitializer.initialize(this.getActivity()); | |
return v; | |
} | |
@Override | |
public void onResume() { | |
mapView.onResume(); | |
super.onResume(); | |
} | |
@Override | |
public void onDestroy() { | |
super.onDestroy(); | |
mapView.onDestroy(); | |
} | |
@Override | |
public void onLowMemory() { | |
super.onLowMemory(); | |
mapView.onLowMemory(); | |
} | |
@Override | |
public void OnMapReady(GoogleMap googleMap) { | |
mMap = googleMap; | |
LatLng monteria = new LatLng(8.7503066, -75.87719299999998); | |
mMap.moveCamera(CameraUpdateFactory.newLatLng(monteria)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.example" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<uses-sdk | |
android:minSdkVersion="8" | |
android:targetSdkVersion="15" /> | |
<uses-permission android:name="android.permission.INTERNET"/> | |
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> | |
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> | |
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> | |
<uses-feature | |
android:glEsVersion="0x00020000" | |
android:required="true"/> | |
<permission | |
android:name="com.example.permission.MAPS_RECEIVE" | |
android:protectionLevel="signature"/> | |
<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/> | |
<application | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme" > | |
<meta-data | |
android:name="com.google.android.maps.v2.API_KEY" | |
android:value="your_key"/> | |
<activity | |
android:name=".HomeActivity" | |
android:label="@string/app_name" > | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment