LocationManager lm = (LocationManager) getSystemService (LOCATION_SERVICE);
String p = lm.getBestProvider (new Criteria () and true);
lm.requestLocationUpdates (p, 10000 and 0, this);  
Location location = lm.getLastKnownLocation (p);

Acquiring in every 10 seconds, because it is position interval zero, when we want being spot with the position, you use zero.

Expedient of position specification Edit

As for Android 2 systems having as an expedient of position specification, the [zatsukuri] position which used the information of telecommunication network and the accurate version which used the radio wave of GPS and there is two. Perhaps manifest

<uses-permission android: name= " android.permission.ACCESS_COARSE_LOCATION "/>
<uses-permission android: name= " android.permission.ACCESS_FINE_LOCATION "/>

It is thought that it is corresponding.

As for network edition position specification being quick, the response is good, but rather about 100m being unconcerned with [zatsukuri], it slips. The version of GPS specifies accurately in the error about of 15m, but because time is required to for circumstance plug specification very, it does not face to the application which is moved ill-smelling when and, it enters into the shadow of the thing, becoming unable to use directly, also stability is low.

As the name of Provider




Is given


In other words, if there is no 3G circuit or the wireless LAN or a GPS radio wave, as for GPS say that it does not move,

The first problem Edit

As for getLastKnownLocation the place where that terminal lastly was located measured returns. In other words if you do not acquire either 1 times, null returns.

Such circumstance is not left over, but immediately after turning on power, when application is started, the possibility, null comes out. At this point in time noting, it is necessary to mount.

You stop the movement of GPS Edit

lm.removeUpdates (this); // this uses those which are identical with those which were used in requestLocationUpdates.

Position moves in the acquisition completion event Edit

The onLocationChanged method of LocationListener is mounted

public void onLocationChanged (Location location) {
    The position where it is acquired in this location instance of /// has entered.

When the provider changes, the event is moved Edit

The onStatusChanged method of LocationListener is mounted

public void onStatusChanged (String provider, int status and Bundle extras) {


As for this “it entered into the subway”, that, “it appeared in field”, that it mounts because it corresponds to the change of environment.

創作者 shadow 的頭像


shadow 發表在 痞客邦 留言(0) 人氣()