我正在努力寻找最可靠的方法来识别用户是开车,步行,骑自行车还是静止不动。我将在Android应用程序中使用它。我宁愿尽可能避免使用GPS。
请让我知道哪些算法适合您,它们的优点和缺点。谢谢!
答案 0 :(得分:1)
Google在Google Play服务中提供了此API。查看https://developer.android.com/reference/com/google/android/gms/location/ActivityRecognitionApi.html
我不会建议你自己编码,这并不容易(我的版本比谷歌早了大约一年,它有漏洞和耗尽电量)。
答案 1 :(得分:0)
您可能永远无法获得完全准确的结果,但可以使用
确定合理的估算值- GPS to identify speed
- Is the charger plugged in
- is the phone off, or on screensaver
- is the movement detector going off a lot - likely walking but may be driving on dirt road
我正在玩这个简单版本如下(抱歉代码在Python中)
def inspect_phone(self):
self.phone_gps_lat = 137.0000 # get from phone
self.phone_gps_lng = 100.0000 # get from phone
self.phone_moving = False # get from phone
self.phone_move_dist_2_mn = 4
self.phone_on_charge = True
self.screen_saver = False
#-------------------------------
phone_status = ''
if self.phone_on_charge == True:
phone_status += 'Phone is charging'
if self.phone_moving == True:
phone_status += ', driving in Car'
else:
phone_status += ', sitting still'
else:
if self.screen_saver == False:
phone_status += 'Phone is being used'
else:
phone_status += 'Phone is off'
if self.phone_moving == True:
if self.phone_move_dist_2_mn < 5:
phone_status += ', going for Walk'
elif self.phone_move_dist_2_mn > 500:
phone_status += ', flying on Plane'
else:
phone_status += ', riding on ' + transport['Public']
return phone_status
答案 2 :(得分:0)
由于我们需要一定数量的经度和纬度才能绘制出用户制作的最佳轨迹,因此我做了一个小的逻辑来为每个活动获得最佳的折线并优化绘图。
让我们说,当用户按下以开始新的活动时,它将提示3个选项,即跑步,步行或骑自行车。
此方法采用用户选择的内容,并更新每个用户的locationRequest。
public void setTrackActivity(long interval, long fastInterval) {
//Update the locationRequest intervals for each different Activity
mLocationRequest.setInterval(interval);
mLocationRequest.setFastestInterval(fastInterval);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
然后,为了在绘制地图时节省更多的折线,我采用了相同的概念。如果用户正在行走,它将在每条已制作的30条多义线处跟踪一条多义线
public void drawTrack(GoogleMap googleMap) {
googleMap.clear(); //Clearing markers and polylines
PolylineOptions polyline_options = new PolylineOptions().addAll(mLinkedList)
.color(ContextCompat.getColor(mContext, R.color.colorAccent)).width(Constants.POLYLINE_WIDTH).geodesic(true);
// Adding the polyline to the map
Polyline polyline = googleMap.addPolyline(polyline_options);
// set the zindex so that the poly line stays on top of my tile overlays
polyline.setZIndex(1000);
// we add each polyline to an array of polylines
mPolylinesArray.add(polyline);
// We add the latest latlang points we got
mLatLngArray.add(mLinkedList.getLast());
//If we have made 30 polylines we store 1 line starting from that first point to the last, so we can save 28 polylines and draw one instead of having so many points for lets say 10 meters, this value must change depending on the activity, if biking, runing or walking
if (mLatLngArray.size() % 30 == 0) {
// First we delete all polylines saved at the array
for (Polyline pline : mPolylinesArray) {
pline.remove();
}
// We create a new polyline based on the first and last latlang from the 30 we took
Polyline routeSoFar = googleMap.addPolyline(new PolylineOptions().color(Color.GREEN).width(Constants.POLYLINE_WIDTH).geodesic(true));
// Draw the polyline
routeSoFar.setPoints(mLatLngArray);
// set the zindex so that the poly line stays on top of my tile overlays
routeSoFar.setZIndex(1000);
// Clear polyline array
mPolylinesArray.clear();
// Add polyline to array
mPolylinesArray.add(routeSoFar);
}
}
mLinkedList
是LinkedList<LatLng>
的地方,因此我们可以拥有第一个元素和最后一个元素(如果要在活动开始时和活动结束时绘制自定义标记)
mPolylinesArray
是Polylines
ArrayList<Polyline>