纬度和经度总是得到零 android 但在 logcat 我得到当前位置
Posted
技术标签:
【中文标题】纬度和经度总是得到零 android 但在 logcat 我得到当前位置【英文标题】:Latitude & Longitude always getting zero android but in logcat i am getting current location 【发布时间】:2012-08-03 07:50:15 【问题描述】:我已经完成了编码,当我按下按钮时,我会收到带有当前位置的邮件
这里是代码
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
所以请任何人告诉我如何获得这个当前位置
【问题讨论】:
您在 androidManifest.xml 中授予权限了吗? 是的先生,我使用了类似下面的权限好的,从你的代码中我发现你写了以下几行,
lat = Integer.parseInt(location.getLatitude()+"");
lang = Integer.parseInt(location.getLongitude()+"");
location.getLagetLatitude()
将写入您正在以整数形式解析的双精度值。
我建议你把 lat,lon 变量设为double
,你的问题就解决了。
【讨论】:
以上是关于纬度和经度总是得到零 android 但在 logcat 我得到当前位置的主要内容,如果未能解决你的问题,请参考以下文章