Center MapView on me

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

Center MapView on me

Postby shiteiru » Thu May 22, 2008 7:00 pm

thats my code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private void initiateView() {
  3.  
  4.         // Get our location
  5.  
  6.         this.myLocation = myLocationManager.getCurrentLocation("gps");
  7.  
  8.        
  9.  
  10.         // Our GPS-Latitude and Longitude Coords
  11.  
  12.         Double lat = TrackerActivity.this.myLocation.getLatitude() * 1E6;
  13.  
  14.         Double lng = TrackerActivity.this.myLocation.getLongitude() * 1E6;
  15.  
  16.        
  17.  
  18.         Point point = new Point(lat.intValue(), lng.intValue());
  19.  
  20.         myMapController.centerMapTo(point, false);
  21.  
  22. }
  23.  
  24.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


simply said.....it doesn' t work at all...i get a nullPointerException...
can' t say why, the code seems correct to me (and i can' t find a hint in the awfull android documentation), at least i get no compiling errors.

Maybe someone can help me out or give me a hint.
shiteiru
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue May 20, 2008 7:16 pm

Top

Postby cadlg » Thu May 22, 2008 7:17 pm

Hi shiteiru

Have you checked if
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.myLocation = myLocationManager.getCurrentLocation("gps");
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

is really returning something ?
cadlg
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Feb 20, 2008 12:33 am
Location: Guatemala

Postby shiteiru » Thu May 22, 2008 8:17 pm

it should, cause i use the coords from

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. this.myLocation = myLocationManager.getCurrentLocation("gps");
  3.  
  4.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


to retrieve my Position and draw it on the map

the thing is......it seems to work with

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. MapPoint mp = new MapPoint(lat.intValue(), lng.intValue());
  3.  
  4.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

but not with
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Point point = new Point(lat.intValue(), lng.intValue());
  3.  
  4.  
  5.  
  6.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


but as a matter of fact i need the second expression to get this line of code to work
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. myMapController.centerMapTo(point, false);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


well guys.....i'm stuck
shiteiru
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue May 20, 2008 7:16 pm

Postby cadlg » Thu May 22, 2008 8:45 pm

which line of code is causing the nullPointerException ?
cadlg
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Feb 20, 2008 12:33 am
Location: Guatemala

Postby shiteiru » Thu May 22, 2008 8:56 pm

this one

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Point point = new Point(lat.intValue(), lng.intValue());
  3.  
  4.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


also it makes no sense at all......at least not to me
shiteiru
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue May 20, 2008 7:16 pm

Postby plusminus » Thu May 22, 2008 9:09 pm

Hello shiteiru,

I do it this way:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         Point p = new Point((int)(this.mMyLocation.getLatitude() * 1E6),
  2.  
  3.                         (int)(this.mMyLocation.getLongitude() * 1E6));
  4.  
  5.         this.mMapView.getController().animateTo(p); // or centerMapTo
Parsed in 0.037 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

Top

Postby shiteiru » Thu May 22, 2008 9:24 pm

well...once again you are my saviour 8)

but still......there is smth that makes no sense at all

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Point p = new Point(lat.intValue(),
  3.  
  4.                lng.intValue());
  5.  
  6.      this.mMapView.getController().animateTo(p); // or centerMapTo
  7.  
  8.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


gives me a nullPointerException (although i declared lat and lng before i use them ^^)

hence

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Point p = new Point((int)(this.mMyLocation.getLatitude() * 1E6),
  3.  
  4.                (int)(this.mMyLocation.getLongitude() * 1E6));
  5.  
  6.      this.mMapView.getController().animateTo(p); // or centerMapTo
  7.  
  8.  
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


works just fine...
shiteiru
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue May 20, 2008 7:16 pm

Postby plusminus » Thu May 22, 2008 11:33 pm

Hello shiteiru,

maybe the Auto-Boxing in Android is not correctly supported (AutoBoxing maps trivial double/ints/... to Double/Integer/... Objects)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Double lat = TrackerActivity.this.myLocation.getLatitude() * 1E6;
Parsed in 0.064 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

The appropriate time for centerMapTo(center)?

Postby liaowg » Wed Jun 04, 2008 7:24 am

I put the call to centerMapTo at the end of onCreate, but get an empty screen, no rendering
liaowg
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Jun 03, 2008 7:26 am

Re: The appropriate time for centerMapTo(center)?

Postby liaowg » Wed Jun 04, 2008 7:35 am

liaowg wrote:I put the call to centerMapTo at the end of onCreate, but get an empty screen, no rendering


After comment the zoomTo call, render happened, too much tricks
liaowg
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Jun 03, 2008 7:26 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests