map.java
import android.os.Bundle; import android.view.View; import android.widget.LinearLayout; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import com.google.android.maps.MyLocationOverlay; public class LocationBasedServicesV1 extends MapActivity { private MapView myMap; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initMap(); initMyLocation(); } /** * Initialise the map and adds the zoomcontrols to the LinearLayout. */ private void initMap() { myMap = (MapView) findViewById(R.id.mymap); View zoomView = myMap.getZoomControls(); LinearLayout myzoom = (LinearLayout) findViewById(R.id.myzoom); myzoom.addView(zoomView); myMap.displayZoomControls(true); } /** * Initialises the MyLocationOverlay and adds it to the overlays of the map */ private void initMyLocation() { MyLocationOverlay myLocOverlay = new MyLocationOverlay(this, myMap); myLocOverlay.enableMyLocation(); myLocOverlay.enableCompass(); myMap.getOverlays().add(myLocOverlay); } @Override protected boolean isRouteDisplayed() { return false; } }
main layout:
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:enabled="true"
android:id="@+id/mymap"
android:apiKey=" mapskey" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myzoom"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
set user permission:
INTERNET
LOCATION.
version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
package="de.itemis.frey.blog.lbsv1"
android:versionCode="100"
android:versionName="1.0.0">
android:icon="@drawable/icon"
android:label="@string/app_name">
android:name=".LocationBasedServicesV1"
android:label="@string/app_name">
android:name="android.intent.action.MAIN" />
android:name="android.intent.category.LAUNCHER" />