Finding co-ordinates of any place in the map

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

Finding co-ordinates of any place in the map

Postby -A- » Wed Mar 09, 2011 11:53 pm

Hello, I'm quite the newbie at Android programming, and so I'll have to ask you to bear with my largely trivial confusions :oops:

I was making an app where a person can put a marker/touch any place on the map, and that takes the co-ordinates of the location and makes it as the title/some other category of a note, where text can be entered. Problem is, I'm not getting exactly how to go about doing this. :oops:

Help would be greatly appreciated.

Thanks.
-A-
Freshman
Freshman
 
Posts: 6
Joined: Wed Mar 09, 2011 11:47 pm

Top

Re: Finding co-ordinates of any place in the map

Postby schofeild » Thu Mar 10, 2011 7:35 am

use this class to get the latitude and longitude:

class MapOverlay extends com.google.android.maps.Overlay
{
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
//---when user lifts his finger---
if (event.getAction() == 1)
{
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Toast.makeText(getBaseContext(),
p.getLatitudeE6() / 1E6 + "," +
p.getLongitudeE6() /1E6 ,
Toast.LENGTH_SHORT).show();
}
return false;
}
}

hope this helps :wink:
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Re: Finding co-ordinates of any place in the map

Postby mohityadav » Fri Mar 11, 2011 6:25 pm

where should i put this piece of code???
when i put it in oncreate method it doesn't work..
rather it gives a warning saying the type MapOverlay is never used locally..
plz help me out
mohityadav
Freshman
Freshman
 
Posts: 2
Joined: Wed Mar 09, 2011 9:21 pm

Re: Finding co-ordinates of any place in the map

Postby schofeild » Sun Mar 13, 2011 4:47 am

put this class after public void onCreate method....it will work then

and make sure u have imported all the relevant packages;
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Re: Finding co-ordinates of any place in the map

Postby -A- » Sun Mar 13, 2011 8:08 am

Thanks for answering schofeild!

I've included the class right after my onCreate method, however, double clicking on the emulator interface does nothing, and no Toast shows.

I've implemented the setBuiltInZoomControls method in my main MapView, is that whats causing the problems? Why does it not respond to touch?
-A-
Freshman
Freshman
 
Posts: 6
Joined: Wed Mar 09, 2011 11:47 pm

Re: Finding co-ordinates of any place in the map

Postby schofeild » Sun Mar 13, 2011 8:27 am

include these 3 statements in ur onCreate method:

MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.add(mapOverlay);
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Top

Re: Finding co-ordinates of any place in the map

Postby -A- » Sun Mar 13, 2011 9:02 am

Thank you! My lack of coding in java is a hindrance right now :(

Could you just explain why you used OverLays and what those 3 lines which you added are doing? Specifically, the last line which you just added.

Noobish question, I know :oops:

Thanks.
-A-
Freshman
Freshman
 
Posts: 6
Joined: Wed Mar 09, 2011 11:47 pm

Re: Finding co-ordinates of any place in the map

Postby schofeild » Sun Mar 13, 2011 9:15 am

Overlays let you add graphical layers over a MapView. You can place as many overlays over the top of the map as you like, each presenting a different level of detail.

for more info:
http://developer.android.com/resources/ ... pview.html
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests