How simply get a GPS Location (that WORKS) into a String...?

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

How simply get a GPS Location (that WORKS) into a String...?

Postby oren78 » Sat Jan 10, 2009 11:42 pm

hello folks,

i've been searching for a long time the net (and also this forum) for a "WORKING" solution that gives me the current GPS Location into a String, so i can work with it...

i don't have the device, i just code on the emulator...anyhow, have someone a helpful hint for me...??
all i got for the moment is this...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 GPSButton.setOnClickListener(new View.OnClickListener()
  2.  
  3.                 {                      
  4.  
  5.                         public void onClick(View v)
  6.  
  7.                         {
  8.  
  9.                                 //departureTextView.setText(getCurrentLocation());                             
  10.  
  11.  
  12.  
  13.                           Log.i("MapView", "calling locationmanager");
  14.  
  15.                           LocationManager lManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  16.  
  17.                          
  18.  
  19.                           String pos;
  20.  
  21.                           Location l;
  22.  
  23.                          
  24.  
  25.                           Log.i("MapView", "reading location");
  26.  
  27.                          
  28.  
  29.                           try                    
  30.  
  31.                           {
  32.  
  33.                                   Log.i("GPS", lManager.getProvider("gps").toString());
  34.  
  35.                                  
  36.  
  37. //                             Log.i("MapView", "Longitude: " +l.getLongitude());
  38.  
  39. //                             Log.i("MapView", "Altitude: " + l.getAltitude());
  40.  
  41. //                             Log.i("MapView", "Latitude: " + (int)l.getLatitude()); // ERROR HERE
  42.  
  43.                           }
  44.  
  45.                           catch (NullPointerException e) {
  46.  
  47.                                Log.e("MapView", "Great...error maybe ACCESS_LOCATION not given");
  48.  
  49.                                departureTextView.setText(getCurrentFakeLocation());
  50.  
  51.                           }                            
  52.  
  53.                                
  54.  
  55.                                 //print("setOnClickListener", this.myLocationManager.getLastKnownLocation("gps").toString());
  56.  
  57.                        
  58.  
  59.                         }
  60.  
  61.                 });
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


and these are my used permissions inside the AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
oren78
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Jan 10, 2009 11:30 pm

Top

Check this

Postby glassfish » Mon Jan 26, 2009 10:43 pm

http://www.anddev.org/viewtopic.php?p=10555#10555

Check out that tutorial if you are working with SDK 1.0

It has more than everything you need. Simply comment out the parts that use the map parts.

Basically, after you have set up the listeners and registered your receivers correctly (see tutorial code), when you call myLocation = myLocationManager.getLastKnownLocation("network") or "gps" if you want to get location using the GPS provider, it gets a location object. Once you have this, you can simply call all the methods on it, such as myLocation.getLatitude(), or myLocation.getLongitude(), etc, which is returned as a double. Obviously to convert it to a string, Double.toString(myLocation.getLongitude())

Good luck.
glassfish
Freshman
Freshman
 
Posts: 9
Joined: Sun Jan 18, 2009 10:23 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests