Mega Code Archive

 
Categories / Android / Core Class
 

Using Google Map

//AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"       package="com.examples.mapper"       android:versionCode="1"       android:versionName="1.0">     <uses-sdk android:minSdkVersion="3" />     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>     <uses-permission android:name="android.permission.INTERNET"></uses-permission>     <application android:icon="@drawable/icon" android:label="@string/app_name">         <activity android:name=".MyActivity"                   android:label="@string/app_name">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                 <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>         <uses-library android:name="com.google.android.maps"></uses-library>     </application> </manifest> //main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="vertical"   android:layout_width="fill_parent"   android:layout_height="fill_parent">   <TextView       android:layout_width="fill_parent"      android:layout_height="wrap_content"     android:gravity="center_horizontal"     android:text="Map Of Your Location"   />   <com.google.android.maps.MapView     android:id="@+id/map"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:enabled="true"     android:clickable="true"     android:apiKey="YOUR_API_KEY_HERE"   /> </LinearLayout> package app.test; import android.os.Bundle; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; public class MyActivity extends MapActivity {     MapView map;     MapController controller;          @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);                  map = (MapView)findViewById(R.id.map);         controller = map.getController();                  LocationManager manager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);         Location location = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);         int lat, lng;         if(location != null) {             //Convert to microdegrees             lat = (int)(location.getLatitude() * 1000000);             lng = (int)(location.getLongitude() * 1000000);         } else {             //Default to Google HQ             lat = 37427222;             lng = -122099167;         }         GeoPoint mapCenter = new GeoPoint(lat,lng);         controller.setCenter(mapCenter);         controller.setZoom(15);     }          //Required abstract method, return false     @Override     protected boolean isRouteDisplayed() {         return false;     } }