Capture Lat/Long after map panning

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

Capture Lat/Long after map panning

Postby gsmith53 » Fri Dec 14, 2007 9:07 am

Ok. I must just be stupid or something.

When the user drags the map around, I want to know what the lat/long of the map center point is and update 2 EditText views with the current lat/long.

I can't seem to find a listener which gets fired on a drag or drop event. Any help would be appreciated.

I have a:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. MapView myMapView = (MapView) findViewById(R.id.myMapView);
  2.  
  3. myMapView.setOnClickListener()
  4.  
  5. {
  6.  
  7.     public void onClick(View v)
  8.  
  9.     {
  10.  
  11.         Point p = myMapView.getMapCenter();
  12.  
  13.         latitudeText.setText(""+(p.getLatitude()/1E6));
  14.  
  15.         longitudeText.setText(""+(p.getLongitude()/1E6));
  16.  
  17.     }
  18.  
  19. };
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


But it never enters that piece of code when the map is dragged...
gsmith53
Freshman
Freshman
 
Posts: 9
Joined: Sat Dec 01, 2007 5:40 am
Location: Dallas, TX

Top

Postby plusminus » Fri Dec 14, 2007 1:34 pm

Hello gsmith53,

android.view.View provides a function called onMotionEvent(...) which should be called, when the user dragged the View. As MapView extends View this should also happen here, but unfortunately id doesn't. Many others have complained about the same problem in the Google Groups.

This is the function, that we would implement in our specialized MapView, if it would be working :( :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  public boolean onMotionEvent(MotionEvent event)
  2. Implement this method to handle MotionEvent events.
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


What you could do is to request and update the Lat/Long periodically in a Thread with Low Priority. Should be no problem, as you calculation is not that cpu-expensive.

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 Edmin66 » Wed Jan 16, 2008 9:22 am

Why don't you retrieve the map center coordinates in the draw() method of your overlay? The method is called to redraw the overlay whenever the map has been panned. So at least as far as finding the map center is concerned this method is as good as onMotionEvent(). It should also be less cpu-expensive than using a seperate monitoring thread, since this thread will also be doing stuff if the map has not been panned.
Edmin66
Freshman
Freshman
 
Posts: 2
Joined: Mon Jan 14, 2008 9:53 pm
Location: Germany

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 5 guests