【发布时间】:2015-11-30 01:01:13
【问题描述】:
我正在尝试制作一个基于谷歌地图在地图上查找最近资源的安卓应用 我将这些资源保存在 SQLite 数据库中 我使用的功能是这样的:
protected void findClosestResources(LatLng mCurrentLocation, GoogleMap map,Context context){
Double currentLatitude=mCurrentLocation.latitude;
Double currentLongitude=mCurrentLocation.longitude;
String selection=Main_Activity.CategorySelect;
//Determine yhe closest resources by substrating Latitude and Longitude
/*Location=Place.rawQuery("SELECT * FROM "+LOCATION_TABLE_NAME+
" WHERE "+selection+
" GROUP BY "+M_COLUMNS[4]+
" HAVING MIN(ABS("+currentLatitude+"-"+M_COLUMNS[1]+")) " +
"AND MIN(ABS("+currentLongitude+"-"+M_COLUMNS[2]+"))",null);*/
if (Location.moveToFirst()) {//select the first row in the cursor object
while (!Location.isAfterLast()) {//verifies if it is the last row
LocationList thisLocation= new LocationList(Location);
getInformationAbout(Location);
PlaceMakerOn(map);
PlaceList.add(thisLocation);
Location.moveToNext();//select the next row
}
Location.close();//close the connection with database
}
乍一看这似乎有效,但仔细检查后结果并不准确。 下图是一个例子:atm 和银行资源被搜索。 而它找到的银行(蓝色标记)确实最接近绿色,而它找到的 ATM(橙色标记)不是
由于银行有 ATM,ATM 标记不应该出现在离银行太远的地方。因为这意味着,根据函数,橙色标记比蓝色标记更接近绿色标记 我该怎么做才能使它更准确?
【问题讨论】:
-
哦,好吧,我猜我不适合问这些问题,因为每次我问一个 android 问题时我似乎都被否决了,而我却不知道为什么:(
-
我已经更新了描述,希望它更清楚(并希望这是投反对票的原因)我希望有人能给我一个解决这个难题的想法
-
我不是反对者,但我有一些建议给你。首先,改进问题的格式; “漂亮”的问题有很长的路要走。问问自己:这是否足以阅读?其次,尽量简洁:不要过度解释与实际问题没有任何联系的情况。去除所有不必要的“噪音”;只问一件事。祝你好运!
-
我虽然还不够清楚,为什么要添加额外的细节并且没有问一件事?我如何优化现有代码以使结果更准确
-
@ridsatrio 这样更好吗?
标签: android google-maps google-maps-api-2