Android Google Map latitude and longitude compression [closed]

谁都会走 提交于 2020-01-07 09:04:15

问题


I am doing one application for Track routes of bike.

I am fetching all the latitude and longitude per second.

Now I want to store that latitude and longitudes in my local database or on server. But the problem is data becomes very large. So I want to store that data with optimization, means I want same result but I want to reduce data size.

Please help me, if anybody knows any algorithm or anything.


回答1:


If you want to do this device-side, there is an open-source maps utility library created by the Android Maps team that includes a method to encode a set of LatLng objects into an encoded Polyline string.

Android Maps Utils library project: https://github.com/googlemaps/android-maps-utils

Sample app that shows how to use the library: https://github.com/googlemaps/hellomap-android

Use this library in your project, then call the PolyUtil.encode() method to encode a set of LatLng objects into a String, which you can store in your database: https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/PolyUtil.java#L68

Then, call PolyUtils.decode() method to decode a set of LatLng objects from the same String: https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/PolyUtil.java#L29




回答2:


The easiest and more practical solution is to reduce the frequency of location updates:

locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,refresh_freq, 0, locListener);

Try to update your position each 3 seconds (refresh_freq = 3000) instead of each one second (refresh_freq = 1000), this will reduce your data to the third. (Considering that the bike speed is not to high, this will not affect your precision)

EDIT: According to your comment in the previous answer, I can understand that you need only to get the speed, and distance. So why don't you only calculate them instantly and overwrite them in each update:

distance = (distance + old_location.distanceTo(new_location));

average_speed = (distance/(total_time/1000))*3.6;

instant_speed =  (((old_location.distanceTo(new_location))/refresh_freq)/1000)

if (instant_speed>max_speed){
max_speed = instant_speed;
}

Insert all of these lines in your onLocationChanged (Location loc) method. Now you won't need to store your positions in a database.



来源:https://stackoverflow.com/questions/17810805/android-google-map-latitude-and-longitude-compression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!