Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/data/AppDataProvider.java
Show First 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | public Cursor query(Uri uri, String[] projection, String selection, | ||||
switch (sUriMatcher.match(uri)){ | switch (sUriMatcher.match(uri)){ | ||||
case LOCATION_SEARCH: | case LOCATION_SEARCH: | ||||
//authority/stops/location/"Lat"/"Lon"/"distance" | //authority/stops/location/"Lat"/"Lon"/"distance" | ||||
//distance in metres (integer) | //distance in metres (integer) | ||||
if(parts.size()>=4 && "location".equals(parts.get(1))){ | if(parts.size()>=4 && "location".equals(parts.get(1))){ | ||||
Double latitude = Double.parseDouble(parts.get(2)); | Double latitude = Double.parseDouble(parts.get(2)); | ||||
Double longitude = Double.parseDouble(parts.get(3)); | Double longitude = Double.parseDouble(parts.get(3)); | ||||
//converting distance to a float to not lose precision | //converting distance to a float to not lose precision | ||||
float distance = parts.size()>=5 ? Float.parseFloat(parts.get(4))/1000 : 0.1f; | float distance = parts.size()>=5 ? Float.parseFloat(parts.get(4))/1000 : 0.02f; | ||||
if(parts.size()>=5) | //if(parts.size()>=5) | ||||
Log.d("LocationSearch"," given distance to search is "+parts.get(4)+" m"); | //Log.d("LocationSearch"," given distance to search is "+parts.get(4)+" m"); | ||||
Double distasAngle = (distance/6371)*180/Math.PI; //small angles approximation, still valid for about 500 metres | Double distasAngle = (distance/6371)*180/Math.PI; //small angles approximation, still valid for about 500 metres | ||||
String whereClause = StopsTable.COL_LAT+ "< "+(latitude+distasAngle)+" AND " | String whereClause = StopsTable.COL_LAT+ "< "+(latitude+distasAngle)+" AND " | ||||
+StopsTable.COL_LAT +" > "+(latitude-distasAngle)+" AND "+ | +StopsTable.COL_LAT +" > "+(latitude-distasAngle)+" AND "+ | ||||
StopsTable.COL_LONG+" < "+(longitude+distasAngle)+" AND "+StopsTable.COL_LONG+" > "+(longitude-distasAngle); | StopsTable.COL_LONG+" < "+(longitude+distasAngle)+" AND "+StopsTable.COL_LONG+" > "+(longitude-distasAngle); | ||||
//Log.d("Provider-LOCSearch","Querying stops by position, query args: \n"+whereClause); | //Log.d("Provider-LOCSearch","Querying stops by position, query args: \n"+whereClause); | ||||
return db.query(StopsTable.TABLE_NAME,projection,whereClause,null,null,null,null); | return db.query(StopsTable.TABLE_NAME,projection,whereClause,null,null,null,null); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register