I'm going to get latitude and longitude of a location on map which user has clicked on and do some calculation on them. BTW I shall say that I'm working with emulator and I don't have access to mobile phone and I have to run it in emulator. Please help me what to do!
3 Answers
Please elaborate your need as this questions is quite confusing. You can show the lat and long values on google map which I guess you are getting from web service or from current location. For using google map on your emulator you will need google map key. Let me know you what type of help you want exactly.
http://blogspot.fluidnewmedia.com/2009/04/displaying-google-maps-in-the-android-emulator/ above link ids good to start with.
- 414
- 3
- 8
You should clarify of what you are using (a Google API, or a image of a map), I am assuming that you are using Java for Android if you are using an image, you can possibly use the
onTouchEvent to find your coordinates then return them on screen as longitude and latitude
as long as you know the longitude and latitude yourself on the map... Please be more descriptive in your questions.
public boolean onTouchEvent(MotionEvent event){
int action = event.getAction();
int x = event.getX()
int y = event.getY();
return yourBoolean;
}
We can not get the current lat and long values in the emulator up to my knowledge. You have to put them your self.Correct me if I am wrong but this is true for that you have to use the real device.
I think this code will help you.Give try on device and let me know.
public class Google_maps extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_maps);
MapView mapview=(MapView)findViewById(R.id.mapView);
mapview.setBuiltInZoomControls(true);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapview.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapview.invalidate();
}
class MapOverlay extends 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;
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}}
- 414
- 3
- 8
-
Ok, I don't have problem with that. My main problem as I said is to find lat and long of the location on the GPS map which user has clicked on, how can I get latitude and longitude of that point? – saeed sargazi Feb 20 '13 at 17:50