Hi, Search in this forum, it has been answered before.
Regards On Jul 13, 4:37 pm, ibrahim yıldırım <ibobis...@gmail.com> wrote: > i am writing an Android app.this application= Works with GPS and > map.it shows the location of.the light > leaves.==.mapView.getController().animateTo(myLocation); you, run this > program........ > > Now, GPS and Map work together. I'm on the road and tries to use GPS > turning left or right. Map is rotate? How is this? Please help. > > main.xml; > -------------------------------- > <?xml version="1.0" encoding="utf-8"?><!-- This file is /res/layout/ > main.xml --> > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ > android" > android:layout_width="fill_parent" > android:layout_height="fill_parent"> > <com.google.android.maps.MapView > android:id="@+id/geoMap" > android:clickable="true" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:apiKey="you key" /> > </RelativeLayout> > ----------------------------------- > AndroidManifest.xml; > ----------------------------------- > <?xml version="1.0" encoding="utf-8"?> > <manifest xmlns:android="http://schemas.android.com/apk/res/android" > package="com.nit.android" > android:versionCode="1" > android:versionName="1.0"> > <uses-sdk android:minSdkVersion="8" /> > > <application android:icon="@drawable/icon" android:label="@string/ > app_name"> > <uses-library android:name="com.google.android.maps" /> > <activity android:name=".MyLocationDemo" > 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> > <uses-permission android:name="android.permission.INTERNET" /> > <uses-permission > android:name="android.permission.ACCESS_FINE_LOCATION" /> > <uses-permission android:name="android.permission.READ_CONTACTS" / > > <uses-permission > android:name="android.permission.ACCESS_NETWORK_STATE" /> > <uses-permission > android:name="android.permission.ACCESS_WIFI_STATE" /> > <uses-permission > android:name="android.permission.READ_PHONE_STATE" /> > <uses-permission > android:name="android.permission.ACCESS_COARSE_LOCATION" /> > </manifest> > > ------------------------------ > java code; > ------------------------------ > public class MyLocationDemo extends MapActivity { > > MapView mapView=null; > MyLocationOverlay whereAmI=null; > LocationListener locListener=null; > LocationManager locMgr=null; > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > mapView=(MapView) findViewById(R.id.geoMap); > mapView.setBuiltInZoomControls(true); > mapView.getController().setZoom(14); > whereAmI=new MyLocationOverlay(this, mapView); > mapView.getOverlays().add(whereAmI); > mapView.postInvalidate(); > > locMgr=(LocationManager)getSystemService(Context.LOCATION_SERVICE); > locListener=new LocationListener() { > > public void onStatusChanged(String provider, int status, > Bundle extras) { > > } > public void onProviderEnabled(String provider) { > } > > public void onProviderDisabled(String provider) { > } > > public void onLocationChanged(Location location) { > showLocation(location); > > } > }; > > } > > @Override > protected boolean isRouteDisplayed() { > return false; > } > > private void showLocation(Location location){ > if(location !=null){ > double lat=location.getLatitude(); > double lng=location.getLongitude(); > > GeoPoint myLocation =new GeoPoint((int)(lat*1e6),(int) > (lng*1e6)); > Toast.makeText(getBaseContext(),"lat:"+lat > +"and"+"long:"+lng, Toast.LENGTH_SHORT).show(); > mapView.getController().animateTo(myLocation); > > } > } > public void onResume(){ > super.onResume(); > Location > lastLoc=locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); > showLocation(lastLoc); > locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, > 1000, 1, locListener); > whereAmI.enableMyLocation(); > whereAmI.runOnFirstFix(new Runnable() { > > public void run() { > // TODO Auto-generated method stub > > mapView.getController().setCenter(whereAmI.getMyLocation()); > } > }); > } > public void onPause(){ > super.onPause(); > locMgr.removeUpdates(locListener); > whereAmI.disableMyLocation(); > } > > > > > > > > } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en