ボタンを押したときに現在の場所でメールを受け取るコーディングを行いました
ここにコードがあります
LocationManager mlocManager = (LocationManager)mContext.getSystemService(Context.LOCATION_SERVICE);
//mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 5.0f, new MyLocationListener());
LocationListener mlocListener = new MyLocationListener();
//mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000,1000,mlocListener);
/*if(mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000,1000,mlocListener);
}
else {
}*/
Criteria criteria = new Criteria();
String provider = mlocManager.getBestProvider(criteria, true);
if(provider!=null) {
Location location = mlocManager.getLastKnownLocation(provider);
if(location!=null) {
lat = Integer.parseInt(location.getLatitude()+"");
lang = Integer.parseInt(location.getLongitude()+"");
}
else
{
mlocManager.requestLocationUpdates(provider, 1, 0, mlocListener);
}
そして今、メールを送信するために
class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
lat = Integer.parseInt(location.getLatitude()+"");
lang = Integer.parseInt(location.getLongitude()+"");
SendMail sender = new SendMail(mContext.getResources().getString(R.string.username), mContext.getResources().getString(R.string.password));
try {
sender.sendMail(
"The Location is ",
" Latitude :- " + lang +
"\n Longitude :-" + lat,
"xxxxx@gmail.com",
"xxxx@gmail.com");
} catch (Exception e) {
e.printStackTrace();
}
}
今、私はメールを受け取っていますが、緯度と経度はゼロです
今、場所を取得していることをlogcatで確認しました
08-03 13:14:45.339: D/libloc(221): Event RPC_LOC_EVENT_PARSED_POSITION_REPORT (client 0)
08-03 13:14:45.339: D/libloc(221): Session status: RPC_LOC_SESS_STATUS_IN_PROGESS Valid mask: 0x6069
08-03 13:14:45.339: D/libloc(221): Latitude: 22.2790718 (intermediate)
08-03 13:14:45.339: D/libloc(221): Longitude: 70.7710290
08-03 13:14:45.339: D/libloc(221): Accuracy: 0.0000000
08-03 13:14:45.339: D/libloc(221): loc_eng_deferred_action_thread signalled
08-03 13:14:45.339: D/libloc(221): loc_eng_deferred_action_thread event 1
08-03 13:14:45.339: D/libloc(221): loc_eng_process_loc_event: 1
08-03 13:14:45.339: D/libloc(221): loc_eng_deferred_action_thread. waiting for events
08-03 13:14:45.469: D/libloc(221): Event RPC_LOC_EVENT_NMEA_1HZ_REPORT (client 0)
08-03 13:14:45.469: D/libloc(221): loc_eng_deferred_action_thread signalled
この現在地を取得する方法を教えてください。