Appendix A. Java code examples referred to in chapter 2

The following listing is an example of the Java code required to fetch the handset location obtained via GPS for use within a Java application.

Listing A.1. Fetching a handset’s location from the inbuilt GPS receiver
Criteria cr = new Criteria();
cr.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW
cr.setAddressInfoRequired(false);
cr.setAltitudeRequired(false);
cr.setSpeedAndCourseRequired(false);
cr.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
cr.setVerticalAccuracy(Criteria.NO_REQUIREMENT);

//cr.setPreferredResponseTime(30);
locationProvider = LocationProvider.getInstance(cr);

The next listing is an example of the Java code required to fetch the handset location obtained via A-GPS for use within a Java application while limiting power consumption.

Listing A.2. Fetching a handset’s location from the inbuilt AGPS receiver
cr.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW
cr.setCostAllowed(MIDlet.useAssistedGPS);
cr.setAddressInfoRequired(false);
cr.setAltitudeRequired(false);
cr.setSpeedAndCourseRequired(false);
cr.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
cr.setVerticalAccuracy(Criteria.NO_REQUIREMENT);

//cr.setPreferredResponseTime(30);
locationProvider = LocationProvider.getInstance(cr);

This listing shows the format in which the cell/get API key returns information on the user’s exact position.

Listing A.3. The cell/get API key will return information in the following format
<rsp stat="ok">
<cell range="6000" lac="0" lat="53.4044704705058" nbSamples="47"
     lon="27.4110088888429" cellId="29513" mcc="250" mnc="99"/>
</rsp>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset