Notes:-
The LocationManager lm and the LocationListener locationListener are declared in the Activity at lines 14 and 15
In Line 24 the LocationManager lm is connected to the LocationService
in line 26 the requestLocationUpdates requests updates from teh GPS system at such and such a frequencey and if the reading is different from the last by so much. When this happens call locationsListener with the Location.
The rest seems quite straightforward line 41 puts the coordinates into a format suitable for pasting into a browser URL to get a Google map.
Using java Syntax Highlighting
- package com.example.hello7;
- import android.app.Activity;
- import android.content.Context;
- import android.location.Location;
- import android.location.LocationListener;
- import android.location.LocationManager;
- import android.os.Bundle;
- import android.util.Log;
- public class Hello7 extends Activity {
- /** Called when the activity is first created. */
- private LocationManager lm;
- private LocationListener locationListener;
- private double mLongitude = 0;
- private double mLatitude = 0;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
- locationListener = new MyLocationListener();
- lm.requestLocationUpdates(
- LocationManager.GPS_PROVIDER,
- 1000, // ms since last call
- 10, // 10 m movement
- locationListener);
- }
- public class MyLocationListener implements LocationListener
- {
- public void onLocationChanged(Location loc) {
- Log.d("Hello7","MyLocationListener");
- if (loc != null) {
- Log.d("Hello7","onLocationChanged not null");
- mLongitude = loc.getLongitude();
- mLatitude = loc.getLatitude();
- String s1 = String.format( "http://maps.google.ca/maps?ll=%f,%f",mLatitude,mLongitude);
- Log.e("Hello7",s1);
- }// loc not null
- }
- public void onProviderDisabled(String provider) {
- // TODO Auto-generated method stub
- }
- public void onProviderEnabled(String provider) {
- // TODO Auto-generated method stub
- Log.d("Hello7","onProviderEnabled");
- }
- public void onStatusChanged(String provider, int status, Bundle extras) {
- }
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
The Android Manifest for this project is:-
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.hello7"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".Hello7"
- 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-sdk android:minSdkVersion="3" />
- </manifest>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4



