안드로이드에서지도를 오랫동안 클릭 한 특정 위치의 위도/경도 값을 어떻게 얻을 수 있습니까?Android에서지도에서 위도와 경도를 얻는 방법은 무엇입니까?
13
A
답변
13
긴 클릭의 경우 http://www.kind-kristiansen.no/2010/handling-longpresslongclick-in-mapactivity/을 확인하시기 바랍니다. 내가 아는 기본 기능이 없기 때문에지도 API에서 긴 클릭 이벤트를 수신하는 방법에 대해 자세히 설명합니다.
위도/경도 코드에 대해서는 긴 클릭을 얻은 후 픽셀을 좌표로 변환 할 수 있습니다.
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
}
4
당신은 LongClick 이벤트를 관리하고, 다음 코드와 경도와 위도를 찾기 위해 코드를 사용해야합니다 :
'이벤트'MotionEvent '의 대상이다GeoPoint geoPoint=mapView.getProjection().fromPixels((int)event.getX(),(int)event.getY());
int latitude = geoPoint.getLatitudeE6();
int longitude = geoPoint.getLongitudeE6();
.
사례에 따라 다른 이벤트를 사용하십시오.
0
이지도의 요점은 내가 다시 잠시 쓴 블로그 게시물에이 응답 포인트
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);
}
});
링크를 클릭하는 위도와 경도를 제공합니다. 방금 더 깨끗하고 잘 작동하는 솔루션으로 새 게시물을 작성했습니다. 관심의 대상 일 수 있습니다 : http://www.kind-kristiansen.no/2011/android-handling-longpresslongclick-on-map-revisited/ – rogerkk