private void GetHerePlaces() {
if (nearPlace.results != null) {
//String placename = "null";
String[] name = new String[60];
double[] distance = new double[60];
int i=0;
int k=0;
// loop through all the places
for (Place place : nearPlace.results) {
//double placedistance;
dest_lat = place.geometry.location.lat; // latitude
dest_lon = place.geometry.location.lng; // longitude
dest_lat = Math.toRadians(dest_lat);
dest_lon = Math.toRadians(dest_lon);
double curr_lat = loc.getLatitude();
double curr_lon = loc.getLongitude();
curr_lat = Math.toRadians(curr_lat);
curr_lon = Math.toRadians(curr_lon);
double R = 6371; // km
double dLon = dest_lon-curr_lon; //Delta Longitude
double dLat = dest_lat-curr_lat; //Delta Latitude
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(curr_lat) * Math.cos(dest_lat) *
Math.sin(dLon/2) * Math.sin(dLon/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
//calculation geographical distance
double d = R * c;
place.distance = d;//내위치와 장소사이의 거리
double y = Math.sin(dLon) * Math.cos(dest_lat);
double x = Math.cos(curr_lat)*Math.sin(dest_lat) -
Math.sin(curr_lat)*Math.cos(dest_lat)*Math.cos(dLon);
//calculation of camera azimuth angle
double bearng = Math.atan2(y, x);
double bearng_deg = Math.toDegrees(bearng);
bearng_deg = (bearng_deg+360) % 360;
place.deg = bearng_deg;//내위치로부터의 각도
//double m = (double)azimuth_deg + cam_angle/2;
//double n = (double)azimuth_deg - cam_angle/2;
double m = (double)azimuth_deg + 5;//cam_angle/4;
double n = (double)azimuth_deg - 5;//cam_angle/4;//정확도를 높이기위해 각도를 좁힘
if(place.deg <= m && place.deg >= n && place.distance > 0.0 && !isUserchoose)//거리가 0.0~50사이위치한 값 표시
{
//List<Double> dist = Arrays.asList(place.distance);
//placedistance = Collections.min(dist);
whereimg.setVisibility(View.INVISIBLE);
distance[i] = place.distance;
name[i] = place.name;
i++;
k++;
//if(place.distance == placedistance)
//{
//sensorDto.setPlaceName(place.name);
//placename = place.name;
//viewPlacename.setText(place.name);
//}
}
if(isUserchoose)
{
//Toast.makeText(this, viewPlacename.getText(), Toast.LENGTH_LONG).show();
whereimg.setVisibility(View.VISIBLE);
//int stop = 1;
if(place.deg + 5 >= azimuth_deg && place.deg -5 <= azimuth_deg && place.distance > 0.0)
{
if(place.name.equals(viewPlacename.getText()))
{
whereimg.setVisibility(View.INVISIBLE);
/*stop = 0;
if(stop == 0)
{
continue;
}*/
}
}
}
}
double min = distance[0];
for(i=1;i<k;i++)
{
if(distance[i]<min)
{
min = distance[i];
}
}
for(i=0;i<k;i++)
{
if(min == distance[i])
{
sensorDto.setPlaceName(name[i]);
viewPlacename.setText(name[i]);
}
if(k==0)
{
viewPlacename.setText("null");
Toast.makeText(this,"이 방향으로 장소가 검색되지 않습니다.", Toast.LENGTH_LONG).show();
}
}
}
}
일단 위의 코드가 지금 만들어놓은 코드인데요
위치기반 카메라 어플입니다.
카메라 전방에 건물을 인식하여(place)를 받아오는 어플인데요
다 괜찮은데 문제점이 전방과 후방을 같이 인식하는것입니다. (카메라 전방,후방)
카메라 전방에만 인식을 시키고 싶은데 너무 모르겠네요 ㅠㅠ