LocationManager

by dave.marsden » Sun, 09 Nov 2008 17:14:58 GMT


Sponsored Links
 I'm trying to get some basic location code working, I've started from
the standard hello world type app, and have changed it to print the
current location. with the following code.

package com.android.tracker;

import android.app.Activity;
import android.os.Bundle;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.widget.TextView;

public class AndroidTracker extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       LocationManager lm =
(LocationManager)getSystemService(Context.LOCATION_SERVICE);

       Location loc = lm.getLastKnownLocation("GPS");
       String pos = loc.toString();
       tv.setText(pos);
       setContentView(tv);
   }
}


However the getLastKnownLocation is returning null in the emulator.
Can anybody tell me what I'm doing wrong?

Thanks

Dave.

--~--~---------~--~----~------------~-------~--~----~



LocationManager

by dave.marsden » Sun, 09 Nov 2008 17:15:07 GMT


 I'm trying to get some basic location based stuff working in the
Android Emulator. using the following code.

package com.android.tracker;

import android.app.Activity;
import android.os.Bundle;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.widget.TextView;

public class AndroidTracker extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       LocationManager lm =
(LocationManager)getSystemService(Context.LOCATION_SERVICE);

       Location loc = lm.getLastKnownLocation("GPS");
       String pos = loc.toString();
       tv.setText(pos);
       setContentView(tv);
   }
}

However getLastKnownLocation is returning NULL, can anybody explain
what I'm doing wrong please?

Thanks

Dave

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


LocationManager

by Christine » Sun, 09 Nov 2008 20:46:05 GMT


 The emulator doesn't have a gps device. If you want to test it, you
have to use the location test tools that come with the sdk. In
Eclipse, there's a tool in DDMS that allows you to enter gps
coordinates for the emulator. Here ( http://kurl.nl ?44FE) is a tool
that converts locations to gps coordinates.

On Nov 8, 9:03pm, "dave.marsden" <[EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~



LocationManager

by Vee » Fri, 09 Jan 2009 00:01:16 GMT


 I was trying to create a mock location manager and i found out that
some of the methods were removed in 1.0 SDK.

Can someone give me a solution on how to implement one? This is just a
sample app i am trying to write, so any help in that regard is helpful
as well.

Thanks !

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Intent loading issue in MenuItem

Hi all,

I have problem with loading google map when click on Menu Item. When click
on menu item every time it give this error:





11-20 14:38:08.877: ERROR/AndroidRuntime(428):
java.lang.NoClassDefFoundError: com.chandana.testcode.ChandanaActivity

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
com.chandana.Test.testcode.loadMap(testcode.java:262)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
com.chandana.Test.testcode.onMenuItemSelected(testcode.java:241)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:139)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:525)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
android.view.View.onTouchEvent(View.java:4179)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
android.widget.TextView.onTouchEvent(TextView.java:6540)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
android.view.View.dispatchTouchEvent(View.java:3709)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
android.view.ViewRoot.handleMessage(ViewRoot.java:1691)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
android.os.Handler.dispatchMessage(Handler.java:99)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
android.os.Looper.loop(Looper.java:123)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
android.app.ActivityThread.main(ActivityThread.java:4363)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
java.lang.reflect.Method.invokeNative(Native Method)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
java.lang.reflect.Method.invoke(Method.java:521)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

11-20 14:38:08.877: ERROR/AndroidRuntime(428):     at
dalvik.system.NativeStart.main(Native Method)

11-20 14:38:10.917: WARN/InputManagerService(58): Got RemoteException
sending setActive(false) notification to pid 428 uid 10026


My Load Map code is:

private void loadMap() {

        Intent mapInt= new Intent(getApplicationContext(),
ChandanaActivity.class);
        this.startActivity(mapInt);

    }

Any one know why this happned?

-- 

2. List child item focus change

Hi All,

I have struck with the below issue.

I have a list view which contains different numbers and i have a
button below with the name "Call".
The expected spec is to change the button background to blue, only if
user clicks on list item,
and if user clicks on some other views, i need to change the button
background to white.

My work around for this issue:

I have set onfocusChangeListener() for the list live,
but onFocusChanged() is getting called if next view gets the focus.

Expected result:

1) Background of the button should change to blue if user clicks on
list child item.
2) Background of the button should change to white if user clicks on
other views.

Can any one help to resolve this issue.

Thanks,
Ajj

--

3. Query on Customs Map application

4. Handling Android device without Menu button

5. Guidelines on using Webview to render UI - getting approval for Market

6. Stopping activity problem

7. Custom view in gallery