110 likes | 431 Views
COMP3670/COMP7090. Location Services – Easier Example. locationManager= (LocationManager)getSystemService(Context.LOCATION_SERVICE ); List<String> providers= locationManager.getAllProviders(); for(String p:providers){ // Process & Provider }. COMP3670/COMP7090.
E N D
COMP3670/COMP7090 Location Services – Easier Example locationManager= (LocationManager)getSystemService(Context.LOCATION_SERVICE); List<String> providers= locationManager.getAllProviders(); for(String p:providers){ //Process & Provider }
COMP3670/COMP7090 Location Services – To find out the best provider Private String findProvider(){ Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAlititudeRequired(false); // criteria.setBearingRequired(false); // criteria.setSpeedRequired(false); //Speed criteria.setCostAllowed(true); // return locationManager.getBestProvider(criteria, ture); }
COMP3670/COMP7090 Location Services – Get the current location • getLastKnownLocation() • //Get the last know location • requestLocationUpdate(String provider, long minTime, float minDistance, LocationListener listener) • minTime://return time • float minDistance:return distance interval. locationManager.requestLocationUpdate(locationManager.AGPS_PROVIDER,60000, 10, new LocationListener(){ public void onLocationChanged(Location location){ //update the position and logic. } });
COMP3670/COMP7090 Location Services – Your Manifest.xml , User-permission <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.ButtonTest" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ButtonTest" 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.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> <uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" /> <uses-permission android:name="android.permission.INTERNET" /> </manifest>
COMP3670/COMP7090 Location Services – Download Google API SDK For further Information, please visit: http://code.google.com/intl/zh-TW/android/add-ons/google-apis/ Remember to use “Android APIs” as a Emulator Some Application may need Android 2.3.3, API 10
COMP3670/COMP7090 Location Services – Google Map API Getting the MD5 Fingerprint of Your Signing Certificate
COMP3670/COMP7090 Location Services – Google Map API For further Information, please visit: http://code.google.com/intl/zh-TW/android/add-ons/google-apis/mapkey.html
COMP3670/COMP7090 Location Services – Google Map API Sign with your MD5 Certificate:http://code.google.com/android/maps-api-signup.html
COMP3670/COMP7090 Location Services – Adding the Maps API Key to your Application Once you've registered with the Google Maps service and have obtained a Maps API Key, you must add it to your application's MapView objects, so that the Maps server will allow them to download Maps tiles. For <MapView> elements declared in XML layout files, add the Maps API Key as the value of a special attribute — android:apiKey. For example: <com.google.android.maps.MapView android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey="example_Maps_ApiKey_String" /> For MapView objects instantiated directly from code, pass the Maps API Key string as a parameter in the constructor. For example: mMapView = new MapView(this, "example_Maps_ApiKey_String"); For more information about MapView, see the MapView class Documentation. http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapView.html
COMP3670/COMP7090 Location Services – Final Steps to Enable MapView Elements If you've added the Maps API Key to the MapViews in your application, here are the final steps to enable the MapView elements to run properly: Make sure that you added a <uses-library> element referencing the external com.google.android.maps library. The element must be a child of the <application> element in the application's manifest. For example: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.package.name"> ... <application android:name="MyApplication" > <uses-library android:name="com.google.android.maps" /> ... </application> Sign your application with the certificate that corresponds to the Maps API Key referenced in your MapView elements. Note that, when you are ready to publish your application, you must get a Maps API Key that is based on the certificate that you will use to sign the application for release. You must then change the Maps API Key strings referenced by all of your MapView elements, so that they reference the new Key.
COMP3670/COMP7090 Try to troubleshot yourself when you copy and paste the text, Import any necessary library, find out what you need in google.