How can I get the Latitude and Longitude values of a particular location that I have long clicked on the map in Android?
如何获取我在Android中长时间点击地图的特定位置的纬度和经度值?
3 个解决方案
#1
13
For the long click, I suggest you check out http://www.kind-kristiansen.no/2010/handling-longpresslongclick-in-mapactivity/. This will go into detail on how to listen for long click events within the Maps API since there is little or no built-in functionality that I know of.
长按一下,我建议您查看http://www.kind-kristiansen.no/2010/handling-longpresslongclick-in-mapactivity/。这将详细介绍如何在Maps API中监听长按事件,因为我知道很少或没有内置功能。
As for the lat/lng code, after you get the long click you can translate the pixels to coordinates.
至于lat / lng代码,在获得长按后,您可以将像素转换为坐标。
public void recieveLongClick(MotionEvent ev)
{
Projection p = mapView.getProjection();
GeoPoint geoPoint = p.fromPixels((int) ev.getX(), (int) ev.getY());
// You can now pull lat/lng from geoPoint
}
#2
4
You'll have to manage the LongClick event, and then use the code to find out longitude and latitude with the following code:
您必须管理LongClick事件,然后使用代码通过以下代码查找经度和纬度:
GeoPoint geoPoint=mapView.getProjection().fromPixels((int)event.getX(),(int)event.getY());
int latitude = geoPoint.getLatitudeE6();
int longitude = geoPoint.getLongitudeE6();
where 'event' is the object of 'MotionEvent'.
其中'event'是'MotionEvent'的对象。
Use any other event according to your case.
根据您的情况使用任何其他事件。
#3
0
It gives latitude and longitude on which point of map click
它给出了点击地图点的纬度和经度
map.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
//myMap.addMarker(new MarkerOptions().position(point).title(point.toString()));
//The code below demonstrate how to convert between LatLng and Location
//Convert LatLng to Location
Location location = new Location("Test");
location.setLatitude(point.latitude);
location.setLongitude(point.longitude);
location.setTime(new Date().getTime()); //Set time as current Date
txtinfo.setText(location.toString());
//Convert Location to LatLng
LatLng newLatLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions()
.position(newLatLng)
.title(newLatLng.toString());
map.addMarker(markerOptions);
}
});
#1
13
For the long click, I suggest you check out http://www.kind-kristiansen.no/2010/handling-longpresslongclick-in-mapactivity/. This will go into detail on how to listen for long click events within the Maps API since there is little or no built-in functionality that I know of.
长按一下,我建议您查看http://www.kind-kristiansen.no/2010/handling-longpresslongclick-in-mapactivity/。这将详细介绍如何在Maps API中监听长按事件,因为我知道很少或没有内置功能。
As for the lat/lng code, after you get the long click you can translate the pixels to coordinates.
至于lat / lng代码,在获得长按后,您可以将像素转换为坐标。
public void recieveLongClick(MotionEvent ev)
{
Projection p = mapView.getProjection();
GeoPoint geoPoint = p.fromPixels((int) ev.getX(), (int) ev.getY());
// You can now pull lat/lng from geoPoint
}
#2
4
You'll have to manage the LongClick event, and then use the code to find out longitude and latitude with the following code:
您必须管理LongClick事件,然后使用代码通过以下代码查找经度和纬度:
GeoPoint geoPoint=mapView.getProjection().fromPixels((int)event.getX(),(int)event.getY());
int latitude = geoPoint.getLatitudeE6();
int longitude = geoPoint.getLongitudeE6();
where 'event' is the object of 'MotionEvent'.
其中'event'是'MotionEvent'的对象。
Use any other event according to your case.
根据您的情况使用任何其他事件。
#3
0
It gives latitude and longitude on which point of map click
它给出了点击地图点的纬度和经度
map.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
//myMap.addMarker(new MarkerOptions().position(point).title(point.toString()));
//The code below demonstrate how to convert between LatLng and Location
//Convert LatLng to Location
Location location = new Location("Test");
location.setLatitude(point.latitude);
location.setLongitude(point.longitude);
location.setTime(new Date().getTime()); //Set time as current Date
txtinfo.setText(location.toString());
//Convert Location to LatLng
LatLng newLatLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions()
.position(newLatLng)
.title(newLatLng.toString());
map.addMarker(markerOptions);
}
});