Map
AndroidManifest.xml
<?xml
version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.adaptive.map"
android:versionCode="1" android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14" />
<uses-permission
android:name="android.permission.INTERNET"></uses-permission>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<activity
android:name=".MapAppActivity"
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:required="true"
android:name="com.google.android.maps" />
</application>
</manifest>
map_activity.xml
<?xml
version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0sZ2uYOryArwt-zf6TeXndgeZH1VMhRxixDGXDg"
/>
</RelativeLayout>
MapAppActivity.java
package
com.adaptive.map;
import
android.content.Context;
import
android.location.Criteria;
import
android.location.Location;
import
android.location.LocationListener;
import
android.location.LocationManager;
import
android.os.Bundle;
import
com.google.android.maps.GeoPoint;
import
com.google.android.maps.MapActivity;
import
com.google.android.maps.MapController;
import
com.google.android.maps.MapView;
public class
MapAppActivity extends MapActivity {
private
MapController mapController;
private MapView
mapView;
private
LocationManager locationManager;
@SuppressWarnings("deprecation")
public void
onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.map_activity);
// bind the layout to the activity
// create a map view
// RelativeLayout
linearLayout = (RelativeLayout)
//
findViewById(R.layout.map_activity);
// Create MapView
mapView =
(MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setStreetView(true);
// Get MapView
Controller
mapController =
mapView.getController();
mapController.setZoom(14);
// Zoom 1 is world view
// Get
LocationManager
locationManager =
(LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Get Location
Provider
String prov =
locationManager.getBestProvider(new Criteria(), true);
// Connect
Location Provider with Location Listener
locationManager.requestLocationUpdates(prov,
0, 0,
new
GeoUpdateHandler());
}
@Override
protected boolean
isRouteDisplayed() {
return false;
}
public class
GeoUpdateHandler implements LocationListener {
@Override
public void
onLocationChanged(Location location) {
int lat = (int)
(location.getLatitude() * 1E6);
int lng = (int)
(location.getLongitude() * 1E6);
GeoPoint point =
new GeoPoint(lat, lng);
mapController.animateTo(point);
// New Map with passed location
//
parameter is drawn
}
@Override
public void
onProviderDisabled(String provider) {
}
@Override
public void
onProviderEnabled(String provider) {
}
@Override
public void
onStatusChanged(String provider, int status, Bundle extras) {
}
}
// Script to
capture Longitude and Latitude
//
javascript:void(prompt('',gApplication.getMap().getCenter()));
}
No comments:
Post a Comment