Cannot communicate with mock GPS

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Cannot communicate with mock GPS

Postby Nuladion » Thu Dec 18, 2008 5:23 pm

Hello everyone,
I tried to code a simple app that will show the user's current location. I read up on how to use the mock GPS in the emulator, but I cannot get it to work.

If I got it right I can send location info to the apps running on the emulator by going to DDMS, select the Emulator in the Devices list, then go to Emulator Control > Location Controls > Manuel, input some coordinates and click Send.
Whenever I do this the log says that it's sent the GPS location (through not every time I click Send) but my app keeps saying 'No location found'...

I've tried various different kinds of code and samples taken from this or other sites, each with no result... so I'm guessing it's something in the communication between the app in the emulator and the mock GPS.
Does anyone have any idea what could be wrong?

Here's the code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.guidokessels.MyCurrentPosition;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.content.Context;
  8.  
  9. import android.location.Criteria;
  10.  
  11. import android.location.Location;
  12.  
  13. import android.location.LocationListener;
  14.  
  15. import android.location.LocationManager;
  16.  
  17. import android.os.Bundle;
  18.  
  19. import android.widget.TextView;
  20.  
  21.  
  22.  
  23. public class MyCurrentPosition extends Activity {
  24.  
  25.     /** Called when the activity is first created. */
  26.  
  27.     @Override
  28.  
  29.     public void onCreate(Bundle savedInstanceState) {
  30.  
  31.         super.onCreate(savedInstanceState);
  32.  
  33.         setContentView(R.layout.main);
  34.  
  35.        
  36.  
  37.         LocationManager locationManager;
  38.  
  39.         String context = Context.LOCATION_SERVICE;
  40.  
  41.         locationManager = (LocationManager)getSystemService(context);
  42.  
  43.        
  44.  
  45.         Criteria criteria = new Criteria();
  46.  
  47.         criteria.setAccuracy(Criteria.ACCURACY_FINE);
  48.  
  49.         criteria.setAltitudeRequired(false);
  50.  
  51.         criteria.setBearingRequired(false);
  52.  
  53.         criteria.setCostAllowed(false);
  54.  
  55.         criteria.setPowerRequirement(Criteria.POWER_LOW);
  56.  
  57.        
  58.  
  59.         String provider = locationManager.getBestProvider(criteria, true);
  60.  
  61.         Location location = locationManager.getLastKnownLocation(provider);
  62.  
  63.        
  64.  
  65.         updateWithNewLocation(location);
  66.  
  67.        
  68.  
  69.         locationManager.requestLocationUpdates(provider, 2000, 10, locationListener);
  70.  
  71.     }
  72.  
  73.    
  74.  
  75.     private final LocationListener locationListener = new LocationListener() {
  76.  
  77.         public void onLocationChanged(Location location) {
  78.  
  79.                 updateWithNewLocation(location);
  80.  
  81.         }
  82.  
  83.        
  84.  
  85.         public void onProviderDisabled(String provider) {
  86.  
  87.                 updateWithNewLocation(null);
  88.  
  89.         }
  90.  
  91.        
  92.  
  93.         public void onProviderEnabled(String provider) { }
  94.  
  95.         public void onStatusChanged(String provider, int status, Bundle extra) { }
  96.  
  97.     };
  98.  
  99.    
  100.  
  101.     private void updateWithNewLocation(Location location) {
  102.  
  103.         String latLongString;
  104.  
  105.         TextView myLocationText;
  106.  
  107.         myLocationText = (TextView)findViewById(R.id.myLocationText);
  108.  
  109.         if(location != null) {
  110.  
  111.                 double lat = location.getLatitude();
  112.  
  113.                 double lng = location.getLongitude();
  114.  
  115.                 latLongString = "Lat: " + lat + "\nLong: " + lng;
  116.  
  117.         } else {
  118.  
  119.                 latLongString = "No location found.";
  120.  
  121.         }
  122.  
  123.         myLocationText.setText("Your current position is:\n" + latLongString);
  124.  
  125.     }
  126.  
  127. }
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


Main.xml contains just one textview with ID = "myLocationText".
I have included the following permissions in my manifest: ACCESS_FINE_LOCATION, ACCESS_MOCK_LOCATION, ACCESS_COARSE_LOCATION.


Regards,
Nuladion
Nuladion
Developer
Developer
 
Posts: 26
Joined: Mon Jun 23, 2008 12:23 pm
Location: Maastricht, Netherlands

Top

Postby dmt » Thu Jan 08, 2009 1:57 am

Did u already try using KML files instead of manual entry?
Somebody else had a similar issue in this forum, my reply to the fellow is here:

http://www.anddev.org/basic_gps_problem-t3725.html
User avatar
dmt
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Jan 05, 2009 6:06 am

Postby Nuladion » Sun Jan 18, 2009 12:58 pm

dmt wrote:Did u already try using KML files instead of manual entry?
Somebody else had a similar issue in this forum, my reply to the fellow is here:

http://www.anddev.org/basic_gps_problem-t3725.html


I'll give it a try. Thanks a lot for your reply!
Nuladion
Developer
Developer
 
Posts: 26
Joined: Mon Jun 23, 2008 12:23 pm
Location: Maastricht, Netherlands

Postby Nuladion » Sun Jan 18, 2009 1:20 pm

It didn't work. I exported a .kml file from Google Earth, loaded it in Eclipse en pressed the Play button. Nothing happens (not even in the log, so I have no idea if it's actually working or not) and it still says "No location found." :/
Nuladion
Developer
Developer
 
Posts: 26
Joined: Mon Jun 23, 2008 12:23 pm
Location: Maastricht, Netherlands

Postby dmt » Mon Jan 19, 2009 9:26 pm

Did u use the exact xml format as described in my post?

try this KML file :
---------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<Placemark>
<name>Pos1</name>
<description>pos1</description>
<LookAt>
<longitude>-119.6569643269722</longitude>
<latitude>35.04470539956493</latitude>
<altitude>0</altitude>
<range>274067.8989160916</range>
<tilt>0</tilt>
<heading>-16.37747875059806</heading>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
<styleUrl>#msn_ylw-pushpin</styleUrl>
<Point>
<coordinates>-122.1387361111111,37.46384722222223,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>pos2</name>
<LookAt>
<longitude>-122.1386696715728</longitude>
<latitude>37.46068337495014</latitude>
<altitude>0</altitude>
<range>1483.960367263456</range>
<tilt>23.87965169588614</tilt>
<heading>-17.83431038244563</heading>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
<styleUrl>#msn_ylw-pushpin</styleUrl>
<Point>
<coordinates>-122.1392330847025,37.46376494158741,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>pos3</name>
<LookAt>
<longitude>-122.1386696477732</longitude>
<latitude>37.46068335214951</latitude>
<altitude>0</altitude>
<range>1488.534638715323</range>
<tilt>23.87965145996164</tilt>
<heading>-17.83431037441389</heading>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
<styleUrl>#msn_ylw-pushpin</styleUrl>
<Point>
<coordinates>-122.1392383942943,37.46327487626981,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>

----------------------------------

it will move your location through 3 points in the Belmont CA area. You can use it to test your emulator.
If it works, simply add your <Placemark> nodes with your own longitude/latitude values.
User avatar
dmt
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Jan 05, 2009 6:06 am

did you ever solve this problem ?

Postby andykalbvleesch » Tue Jan 20, 2009 10:59 pm

I am also struggling with this issue... If you solved the problem please let me know because it is driving met nuts...
andykalbvleesch
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Jan 20, 2009 2:36 pm

Top

try this

Postby ralphie » Wed Jan 21, 2009 5:55 am

For now, try 0 for minumum time between updates and minimum distance. You can even just put "gps" in the provider name

locationManager.requestLocationUpdates("gps", 0, 0, locationListener);

Also, skip the ddms. telnet into your emulator (telnet localhost 5554) and use the "geo fix" command as described here:
http://code.google.com/android/toolbox/apis/lbs.html

Shift your waypoint every time, it may not update you if you just send in the same location. I find the simulation finicky and I get best result if I close out and reopen the telnet session every once-in-a-while. I use a script to pipe in waypoints periodically.

GoodLuck
ralphie
Freshman
Freshman
 
Posts: 4
Joined: Wed Nov 12, 2008 5:45 am
Location: Bay Area, CA

Doesn't work either

Postby andykalbvleesch » Wed Jan 21, 2009 10:47 am

I have a G1 where I can test the code so no need for the emulator. However the code doesn't work. It does start up GPS because I can see the GPS icon on the top... But then it says no location found.

Does anybody have some working code where you can pick up GPS lat lon ?
andykalbvleesch
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Jan 20, 2009 2:36 pm

Postby Nuladion » Thu Jan 22, 2009 4:01 pm

dmt wrote:Did u use the exact xml format as described in my post?

[kml]

it will move your location through 3 points in the Belmont CA area. You can use it to test your emulator.
If it works, simply add your <Placemark> nodes with your own longitude/latitude values.


It didn't work, so I guess there's something wrong in the java code.

ralphie wrote:For now, try 0 for minumum time between updates and minimum distance. You can even just put "gps" in the provider name

locationManager.requestLocationUpdates("gps", 0, 0, locationListener);

Also, skip the ddms. telnet into your emulator (telnet localhost 5554) and use the "geo fix" command as described here:
http://code.google.com/android/toolbox/apis/lbs.html

Shift your waypoint every time, it may not update you if you just send in the same location. I find the simulation finicky and I get best result if I close out and reopen the telnet session every once-in-a-while. I use a script to pipe in waypoints periodically.

GoodLuck


I have no experience with using telnet... how does this work?

Edit: By using PuTTY and sending the command "geo fix -121.45356 46.51119 4392" it works perfectly in Google Maps, but not in my app. So I guess the code's broken :( But at least now I know how to send GPS signals to the emulator! Thanks a lot for the telnet suggestion! Does someone have the correct code for getting the user's GPS position?
Nuladion
Developer
Developer
 
Posts: 26
Joined: Mon Jun 23, 2008 12:23 pm
Location: Maastricht, Netherlands

Did you try this?

Postby ralphie » Sat Jan 24, 2009 4:49 am

locationManager.requestLocationUpdates("gps", 0, 0, locationListener);

I think you are not getting a provider because of the criteria you setup. I never did that, and I would not expect it to work. Of course if might, but I know the above line will work... I would do a little more debugging by stepping the code. I bet your "location not found is due to this code...

public void onProviderDisabled(String provider) {
updateWithNewLocation(null);
}


Use the logging feature so you can get some info out. Your code is basically correct best I can tell. I think it is something silly. I would definitely try this line instead of yours...

locationManager.requestLocationUpdates("gps", 0, 0, locationListener);

good luck
ralphie
Freshman
Freshman
 
Posts: 4
Joined: Wed Nov 12, 2008 5:45 am
Location: Bay Area, CA

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 6 guests