First of all, the acquisition of GPS data positioning methods are: GPS satellite positioning, WiFi location, base station positioning, AGPS positioning. The application of GPs is regarded as the core in the software of lbs industry. Several positioning ways to explain
(1)Android GPS: the need for GPS hardware support, direct and satellite interaction to obtain the current latitude and longitude, this way requires mobile phone support GPS module (now most of the smart machines should have). The accuracy of GPS is the highest, but its shortcomings are also very obvious: 1, compare power consumption; 2, the majority of users do not open the GPS module by default, 3, from the GPS module to obtain the first location data, it may take a long time; 4, the room is almost unusable. Among them, the shortcoming 2,3 all is more fatal. It should be pointed out that the GPS is going to the satellite communication channel, in the absence of network connectivity can also be used.
(2)Android WiFi location: According to a fixed wifimac address, through the location of the WiFi hotspot collected, and then access to the network location services to obtain latitude and longitude coordinates. Because it and the base station localization actually all need to use the network, therefore in the Android also collectively is the network way.
(3)Android Base station positioning:Android Base station positioning as long as you understand the base station/wifi positioning principle, it is not difficult to achieve the base station/wifi positioning. Base station location is generally several, the first is to use the mobile phone near the three base stations for triangulation, since the position of each base station is fixed, it takes time to calculate the coordinates of the mobile phone by using electromagnetic wave to transfer between the three base stations; the second is to use the information from the nearest base station, including the base station ID, Location area code, mobile country Code, mobile network code, and signal strength, send the data to Google's location-based Web service, where it can get the current location information, usually within dozens of meters to hundreds of meters.
(4)AGPS positioning:AGPS (ASSISTEDGPS: Auxiliary global satellite positioning System) is the combination of GSM or GPRS and traditional satellite positioning, the use of Base station to send auxiliary satellite information to reduce the GPS chip acquisition satellite signal delay time, The covered interior can also be compensated by the base station signal, reducing the reliance of GPS chips on satellites. Compared with pure GPS and base-station triangulation, AGPS can provide a wide range, more energy-saving, faster positioning services, the ideal error range within 10 meters, Japan and the United States have matured the use of aGPS in lbs service (Location Based service, location-based services). aGPS technology is a kind of technology which combines network base station information and GPS information to locate mobile station, which can be used in Gsm/gprs, WCDMA and CDMA2000 networks. The technology needs to increase the GPS receiver module in the mobile phone, and transform the mobile phone antenna, at the same time in the mobile network to add location servers, differential GPS reference stations and other equipment. The advantages of AGPS solution are mainly embodied in its positioning accuracy, in outdoor and other open areas, its accuracy in the normal GPS working environment, can reach about 10 meters, is the highest positioning accuracy of a positioning technology. Another advantage of the technology is that the first time it takes a GPS signal to take only a few seconds, unlike GPs, the first capture time can be 2-3 minutes.
To sum up, the optimal solution should be AGPS positioning, because it saves time (fast positioning time), power saving, high precision, higher acceptance. Realization of logic conception of GPS data acquisition
(1), the realization of GPS data localization: the use of sqlite according to a certain time frequency (general 10s, 15s, 20s, 30s can even larger, depending on the amount of application data, Generally the same time to gather more points so it is easier to describe this period of time GPS device movement trajectory acquisition of GPs to the local SQLite database storage.
(2), the realization of GPS data timing upload: Every half hour, periodically to the server thrown thread (with asynchronous thread) to perform local data to remote server synchronization operations.
(3), registration service and allow in app backstage: use Broadcastreceiver to register Local Service (data acquisition) and remote service (upload). Implementing feature Requirements Create Local-service local GPS data acquisition Service,systemlocalservice.java
Package com.boonya.wtms.service;
Import com.boonya.wtms.domain.GPSLocation;
Import com.boonya.wtms.utils.Constant;
Import Com.boonya.wtms.utils.DateParser;
Import Android.app.Service;
Import Android.content.Context;
Import android.content.Intent;
Import Android.location.Criteria;
Import android.location.Location;
Import Android.location.LocationListener;
Import Android.location.LocationManager;
Import Android.os.Bundle;
Import Android.os.IBinder;
public class Systemlocalservice extends Service {static Locationmanager Loctionmanager;
static String provider;
Private Gpslocationservice Gpslocationservice;
Context tag = Systemlocalservice.this;
@Override public void OnCreate () {super.oncreate ();
Obtain the GPS position processing class instance Gpslocationservice = new Gpslocationservice (tag);
@Override public IBinder onbind (Intent arg0) {return null; }//Position listener @Override @Deprecated public void OnStart (Intent Intent, int startid) {//Start GPS monitoring Initgpslocationlis
Tener (); Super.OnStart (Intent, Startid);
@Override public void OnDestroy () {//rewritten OnDestroy method Loctionmanager.removeupdates (Locationlistener);
Super.ondestroy (); Private final Locationlistener Locationlistener = new Locationlistener () {@Override public void onstatuschanged
(String provider, int status, Bundle extras) {} @Override public void onproviderenabled (String provider) {} @Override public void onproviderdisable D (String provider) {}//When position changes trigger @Override public void onlocationchanged (Location Location) {if loca
tion!= null) {thread thread = new Thread (new Docollectthread (location));
Thread.Start ();
}
}
};
/** * Initialize GPS position monitor/protected void Initgpslocationlistener () {String contextservice = Context.location_service;
Through the system service, obtains the Locationmanager object Loctionmanager = (Locationmanager) getsystemservice (Contextservice); 3. The location provider, the location provider, the location information, the specific location provider can be specified, and a standard set can be provided to match the most suitable location provider according to/to the standard, bitThe placement information is provided by the location supplied by it.
A. Obtain a location via a GPS position provider (Specify a specific location provider)//String Provider = Locationmanager.gps_provider;
Location Location = loctionmanager.getlastknownlocation (provider);
B. Use of standard collections to allow the system to automatically select the best available location provider and to provide a location criteria = new criteria ();
Criteria.setaccuracy (criteria.accuracy_fine);//High precision criteria.setaltituderequired (true);/Required elevation Criteria.setbearingrequired (TRUE);//Required Azimuth criteria.setspeedrequired (true); Request Speed criteria.setcostallowed (true);//Allow cost criteria.setpowerrequirement (criteria.power_low);//low power//from available locations
In the supply, the best provider Provider = Loctionmanager.getbestprovider (criteria, true) that matches the above criteria;
Get the position of the last change//Location Location = loctionmanager.getlastknownlocation (provider); Finally, the position information is displayed in TextView, such as://Monitor position change//monitor position changes, 2 seconds, distance 10 meters above loctionmanager.requestlocationupdates (provider, Const Ant.
Gps_collect_time, Constant.gps_collect_distance, Locationlistener); /** * Local GPS collection Data warehousing to SQLite * * @author boonya * * * @having-LIne---------------------------------------------------------* @filename Systemlocalservice.java * @function TODO * @start-at 2014-12-11, PM 4:47:14 * @having-line---------------------------------------------------------* * Class doco
Llectthread implements Runnable {Location Location;
Public Docollectthread (Location Location) {this.location = Location; @Override public void Run () {gpslocation gpslocation = new Gpslocation ( -1, Location.getlatitude (), LOCATION.G
Etlongitude (), Location.getaltitude (), location.getbearing (), Location.getspeed (), Dateparser.getsystemdatestr ());
Gpslocationservice.savetolocal (gpslocation); }
}
}
Create Remote-serviceSynchronizing local tasks to the service side Service,systemremoteservice.java
Package com.boonya.wtms.service;
Import java.util.List;
Import Java.util.Timer;
Import Java.util.TimerTask;
Import com.boonya.wtms.domain.GPSLocation;
Import com.boonya.wtms.utils.Constant;
Import Android.app.Service;
Import Android.content.Context;
Import android.content.Intent;
Import Android.os.IBinder;
public class Systemremoteservice extends Service {context tag = systemremoteservice.this;
Private Gpslocationservice Gpslocationservice;
@Override public void OnCreate () {super.oncreate ();
Gpslocationservice=new Gpslocationservice (tag);
@Override public IBinder onbind (Intent arg0) {return null;
@SuppressWarnings ("deprecation") @Override public void OnStart (Intent Intent, int startid) {doservice ();
Super.onstart (Intent, Startid); } protected void Doservice () {//Dispatch task executes new Timer (). Schedule (new TimerTask () {@Override public void R Un () {//save local GPS data to remote server list<gpslocation> Gpslocations=gpslocationserviCe.findall ();
Boolean flag=gpslocationservice.savetoserver (Gpslocations);
if (flag) {//delete the uploaded GPS data gpslocationservice.delete (gpslocations);
}}, 0, constant.gps_thread_time_wait); }
}
Create System Broadcastreceiver
Package com.boonya.wtms.service;
Import Android.content.BroadcastReceiver;
Import Android.content.Context;
Import android.content.Intent;
Import Android.util.Log;
public class Systembroadcastreceiver extends Broadcastreceiver
{
@Override public
void OnReceive Context, Intent Intent)
{
//Call service
Context.startservice (new Intent (" Com.boonya.wtms.service.System_LocalService "));
LOG.I ("Device-gps-local-service", "GPS local acquisition service launch success!");
Invoke Service
Context.startservice (new Intent ("Com.boonya.wtms.service.System_RemoteService"));
LOG.I ("Device-gps-remote-service", "GPS remote Upload service started successfully!");
}
registering receiver and service in Androidmanifest.xml
<receiver android:name= "Com.boonya.wtms.service.SystemBroadcastReceiver" > <intent-filter> <action android:name= "Android.intent.action.BOOT_COMPLETED"/> <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </receiver> &L
T;service android:name= "Com.boonya.wtms.service.SystemRemoteService" > <intent-filter> <action android:name= "Com.boonya.wtms.service.System_RemoteService"/> <category android:name= "Android.intent.category.DEFAULT"/> </intent-filter> </service> <service Droid:name= "Com.boonya.wtms.service.SystemLocalService" > <intent-filter> <action Android:name= "Com.boonya.wtms.service.System_LocalService"/> <category android:name= "Android.inten" T.category.default "/> </intent-filter> </service>
Join Access settings Permission
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE" > </uses-permission> <use S-permission android:name= "Android.permission.ACCESS_COARSE_LOCATION" > </uses-permission> <uses-permi Ssion android:name= "Android.permission.INTERNET" > </uses-permission> <uses-permission android:name= "a Ndroid.permission.ACCESS_MOCK_LOCATION "> </uses-permission> <!--<uses-permission Android:name=" Droid.permission.WRITE_APN_SETTINGS "></uses-permission>--> <uses-permission android:name=" Android.permission.ACCESS_FINE_LOCATION "> </uses-permission> <uses-permission android:name=" Com.andro Id.launcher.permission.READ_SETTINGS "/> <uses-permission android:name=" Android.permission.WAKE_LOCK "> & lt;/uses-permission> <uses-permission android:name= "Android.permission.CHANGE_WIFI_STATE"/> <uses-per Mission Android:name= "Android.permisSion. Access_wifi_state "/> <uses-permission android:name=" Android.permission.ACCESS_GPS "/>"
Note: GPS acquisition uses satellite positioning (satellite discovery is time-consuming during the acquisition process, and uncertainty, sometimes a few minutes are connected, sometimes half an hour, or even not even at all, this depends on the Android GPS module manufacturer, the above permissions may not be complete, this does not make corrections.
about the performance considerations(1), local storage SQLite storage capacity: The assumption that an object in the SQLite occupy 1kB, then 1000 objects about 1MB, and SQLite is suitable for the small amount of data storage, then 1000, 1500 can also be normal storage. Generally, it is recommended that no more than 500 (500KB) data be appropriate, after all, this is a miniature (mini) database. (2), reduce the storage pressure on the remote server: Given the limited storage capacity of SQLite, local data to the server is a problem: storage, dense storage (complexity O (n)) or hash storage (complexity O (1)), which is a key factor in performance considerations. Instead of using hash as a real hash store, this is a way to use queues to distribute storage pressure.