Get coordinates

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

Get coordinates

Postby pedroteixeira07 » Wed Jun 23, 2010 11:49 am

Hello,

I'm trying to build a piece of code that gives me back the latitude and longitude of the top/left and the bottom/right screen.

I need this values to know which piece of the map is being shown to the user. Hw can I get this? I mean is it possible to convert the pixels being displayed to latitude/ longitude? does anyone have any tutorial or suggestion on this?

Im able to get the latitude/longitude from the center of the screen, maybe I can get it from here ? Thank you
pedroteixeira07
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Sun Oct 18, 2009 6:06 pm
Location: Funchal

Top

Re: Get coordinates

Postby vik » Thu Jun 24, 2010 5:36 pm

i dunno about how to fetch top/left and right/bottom co- ord but i know how to interpret the pixels into geo point which can give you co ordinates



GeoPoint coords = mapView.getProjection().fromPixels((int) event.getX(), (int) event.getY());

i have used this line on ItemizedOverlay's ontouchevent ...
mite help you out
User avatar
vik
Senior Developer
Senior Developer
 
Posts: 141
Joined: Wed Sep 09, 2009 7:32 am

Re: Get coordinates

Postby endhck » Tue Jul 20, 2010 9:43 am

hi
I am trying to change location of my marker, when i clicked somewhere my marker must come that location.
I added a ontouchlistener to mapView and used your code:
GeoPoint coords = mapView.getProjection().fromPixels((int) event.getX(), (int) event.getY());
It works like I wanted but it works only one time. I need everytime I clicked somewhere there must be this change.
How I can get it?
endhck
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Jul 06, 2010 3:20 pm

Re: Get coordinates

Postby endhck » Thu Jul 22, 2010 2:50 pm

in onTouch method, you should return true. When you do this, whenever you click the map this method is invoked.
endhck
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Jul 06, 2010 3:20 pm

Re: Get coordinates

Postby pranav09 » Sat Aug 07, 2010 7:35 am

Hi endhck,

When you touch anywhere on the map, you can get latitude, longitude, address of that location, etc.,

Just follow the below code. Hope!, you will get solution and let me know, if you get.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         public boolean onTouchEvent(MotionEvent event, MapView mapView)
  3.         {  
  4.                 //---when user lifts his finger---
  5.                 if (event.getAction() == 1)
  6.                 {                
  7.                         GeoPoint p = mapView.getProjection().fromPixels(
  8.                                         (int) event.getX(),
  9.                                         (int) event.getY());
  10.  
  11.                         Geocoder geoCoder = new Geocoder(
  12.                                         getBaseContext(), Locale.getDefault());
  13.                         try
  14.                         {
  15.                                 List<Address> addresses = geoCoder.getFromLocation(
  16.                                                 p.getLatitudeE6()  / 1E6,
  17.                                                 p.getLongitudeE6() / 1E6, 1);
  18.  
  19.                                 String add = "";
  20.                                 if (addresses.size() > 0)
  21.                                 {
  22.                                         for (int i=0; i<addresses.get(0).getMaxAddressLineIndex(); i++)
  23.                                         {
  24.                                                 add += addresses.get(0).getAddressLine(i) + "\n";
  25.                                         }
  26.                                 }
  27.                                 Toast.makeText(getBaseContext(), add, Toast.LENGTH_LONG).show();
  28.                         }
  29.                         catch (IOException e)
  30.                         {                
  31.                                 e.printStackTrace();
  32.                         }
  33.                        
  34.                         return true;
  35.                 }
  36.                 else
  37.                 {
  38.                         return false;
  39.                 }
  40.         }        
  41.     }
  42.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Thanks.
Pranav
User avatar
pranav09
Senior Developer
Senior Developer
 
Posts: 128
Joined: Mon Jan 19, 2009 12:01 pm
Location: Ahmedabad, India

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 1 guest