Own GPS-Location

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

Own GPS-Location

Postby shiteiru » Tue May 20, 2008 7:21 pm

Atm i'm kinda frustrated. I tried many different things looked many tutorials over and over, but i just can't get it to work...

Here's the code im talkin about. I probably got something wrong, but i just can't find what it is.

Everytime i start my app i get a nullPointer Exception

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 this.myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  3.  
  4.  
  5.  
  6.                 this.myLocation = this.myLocationManager.getCurrentLocation("gps");
  7.  
  8.                
  9.  
  10.                  Double lat = TrackerActivity.this.myLocation.getLatitude() * 1E6;
  11.  
  12.                  Double lng = TrackerActivity.this.myLocation.getLongitude() * 1E6;
  13.  
  14.  
  15.  
  16.                  MapPoint mp = new MapPoint(lat.intValue(), lng.intValue());
  17.  
  18.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


maybe someone can help me out on this...
shiteiru
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue May 20, 2008 7:16 pm

Top

Postby plusminus » Tue May 20, 2008 7:24 pm

Hello shiteiru,

did you add the permissions you need to the AndroidManifest.xml also check the LogCat if it prints something about Permission-Issues.

Permissions in AndroidManifest.xml should look similar to these:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    package="your.package.structure">
  6.  
  7.     <uses-permission android:name="android.permission.ACCESS_LOCATION"/>
  8.  
  9.     <uses-permission android:name="android.permission.ACCESS_GPS"/>
  10.  
  11.     <application android:icon="@drawable/icon">
  12.  
  13. ...
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby shiteiru » Tue May 20, 2008 7:55 pm

whoohooooo

it works!!!

a big thanks for this plusminus !!!
shiteiru
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue May 20, 2008 7:16 pm

Postby plusminus » Thu May 22, 2008 11:19 am

No problem :D
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby alex2308 » Wed Jun 18, 2008 3:37 pm

im having some similar problems, too. i get nullpointer exceptions when reading latitude - ONLY when reading latitude. longitude works fine, so does altitude. veeery strange behavior. am i missing some permissions?

i did add "android.permission.ACCESS_LOCATION" and "android.permission.ACCESS_ASSISTED_GPS" using eclipse IDE.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 Log.i("MapView", "calling locationmanager");
  3.  
  4.                 LocationManager lManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  5.  
  6.                
  7.  
  8.                 String pos;
  9.  
  10.                 Location l;
  11.  
  12.                
  13.  
  14.                 Log.i("MapView", "reading location");
  15.  
  16.                 l = lManager.getCurrentLocation("agps");
  17.  
  18.                 try {
  19.  
  20.                         Log.i("MapView", "Longitude: " +l.getLongitude());
  21.  
  22.                         Log.i("MapView", "Altitude: " + l.getAltitude());
  23.  
  24.                         Log.i("MapView", "Latitude: " + (int)l.getLatitude()); // ERROR HERE
  25.  
  26.                 }
  27.  
  28.                 catch (NullPointerException e) {
  29.  
  30.                         Log.e("MapView", "Great...error maybe ACCESS_LOCATION not given");
  31.  
  32.                 }
  33.  
  34.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
alex2308
Developer
Developer
 
Posts: 34
Joined: Wed Jun 11, 2008 1:37 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests