안드로이드 개발 질문/답변
(글 수 45,052)
private OceanData getMostShortestData(GeoPoint point1,
List<OceanData> tmpList) {
Location curLoc = new Location("currentLocation");
curLoc.setLatitude(point1.getLatitudeE6());
curLoc.setLongitude(point1.getLongitudeE6());
Location tmpLocation = null;
float distance = 0; //가장 가까운 거리
float tmpDistance = 0;
OceanData mostShortestOceanData = null;
for (OceanData oceanData : tmpList) {
tmpLocation = new Location("tmpLoc");
tmpLocation.setLatitude(oceanData.getLat());
tmpLocation.setLongitude(oceanData.getLon());
tmpDistance = curLoc.distanceTo(tmpLocation);
if( 0 == distance || distance > tmpDistance){
distance = tmpDistance;
mostShortestOceanData = oceanData;
}
}
return mostShortestOceanData;
}이렇게 gps 내좌표와의 가장 가까운 거리좌표를 구하는 로직입니다~
에러는 나지 않고 어느 한곳을 찍긴합니다..
그런데 그게 gps와 가장 가까운 점이 아니라는게 문제입니다.
이렇게 짜면 가장 가까운 점을 가져와야 하는것이 아닐까요..흠..
엉뚱한 점을 가져오노우우우우.ㅠㅠ
SMS 입니다.
2010.11.29 12:27:44
curLoc.setLatitude(point1.getLatitudeE6() * 1E6); 처럼 IE6 곱을 해서 한번 해보십시오.
Location.setLatitude 파라미터 데이터 타입이 double 이고, GeoPoint.getLatitudeE6 리턴타입은 int 쟎아요.
2010.11.29 13:10:11
안녕하세요 답변 감사드립니다. 점심은 맛있게 드셧는지요.^^;
답변주신 대로 *1E6 붙여서 했으나 또 다른 지점인 더 먼곳을 가리키네요. 서로 좌표계가 맞지 않아서 그런지
데이터 타입이 맞지 않아서 그런건지..흠..
답변주신 대로 *1E6 붙여서 했으나 또 다른 지점인 더 먼곳을 가리키네요. 서로 좌표계가 맞지 않아서 그런지
데이터 타입이 맞지 않아서 그런건지..흠..
2010.11.29 13:13:20
표시는 이렇게 하고있습니다.
GeoPoint point1 = new GeoPoint((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6));
OceanData mostShortest = getMostShortestData(point1, tmpList);
Log.d("mostShortestOceanData", String.valueOf(mostShortest.getLat()));
Log.d("mostShortestOceanData", String.valueOf(mostShortest.getLon()));
GeoPoint mostShortestPoint = new GeoPoint(mostShortest.getLat(),mostShortest.getLon());
OverlayItem overlayitem = new OverlayItem(mostShortestPoint, "GPS 정보!", " 가장 가까운 위치");
itemizedoverlay.addOverlay(overlayitem);
Drawable curD = this.getResources().getDrawable(R.drawable.icon2);
GMapOverlay curO = new GMapOverlay(curD,this);
OverlayItem CurOI = new OverlayItem(point1, "GPS 정보!", " 현재의 위치입니다.");
curO.addOverlay(CurOI);
mc.setCenter(point1);
// mapController.animateTo(point1);
mapOverlays.add(itemizedoverlay);
mapOverlays.add(curO);
GeoPoint point1 = new GeoPoint((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6));
OceanData mostShortest = getMostShortestData(point1, tmpList);
Log.d("mostShortestOceanData", String.valueOf(mostShortest.getLat()));
Log.d("mostShortestOceanData", String.valueOf(mostShortest.getLon()));
GeoPoint mostShortestPoint = new GeoPoint(mostShortest.getLat(),mostShortest.getLon());
OverlayItem overlayitem = new OverlayItem(mostShortestPoint, "GPS 정보!", " 가장 가까운 위치");
itemizedoverlay.addOverlay(overlayitem);
Drawable curD = this.getResources().getDrawable(R.drawable.icon2);
GMapOverlay curO = new GMapOverlay(curD,this);
OverlayItem CurOI = new OverlayItem(point1, "GPS 정보!", " 현재의 위치입니다.");
curO.addOverlay(CurOI);
mc.setCenter(point1);
// mapController.animateTo(point1);
mapOverlays.add(itemizedoverlay);
mapOverlays.add(curO);
2010.11.29 13:43:17
http://snippets.dzone.com/posts/show/10687
여기 참고해서 사용하고 있는데요. 파라미터 타입 bouble 은 GeoPoint 위경도 int 값을 IE6으로 나누어서 대입해주시면 됩니다.



