关于定位的问题,整的自己快疯了,googlemap问题

麦田捕手 2010-11-12 11:41:00
下了“深入浅出google android”这本书中的有关googlemap相关的几个demo源码,其中一个最简单的是获取当前经纬度,
就一个类,
public class CurrentLocation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager locationManager;
String serviceName = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(serviceName);
//String provider = LocationManager.GPS_PROVIDER;

Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);

Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider, 2000, 10,
locationListener);
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
public void onProviderEnabled(String provider){ }
public void onStatusChanged(String provider, int status,
Bundle extras){ }
};
private void updateWithNewLocation(Location location) {
String latLongString;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "纬度:" + lat + "\n经度:" + lng;
} else {
latLongString = "无法获取地理信息";
}
myLocationText.setText("您当前的位置是:\n" +
latLongString);
}
}

我直接倒入到eclipse里,然后通过真机测试,竟然提示“无法获取地理信息”(G5,设置正常),模拟器测试也是“无法获取地理信息”,不知道怎么回事,请高手指点指点(相关源码
...全文
1130 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgycsmb 2012-01-15
  • 打赏
  • 举报
回复
楼主,我也需要实现此功能,
你能把此例子发一份给我email吗 350038760@qq.com thanks
Serena_mm 2011-09-05
  • 打赏
  • 举报
回复
这个问题也困扰了我很久,一直没找到答案,帮顶~
ameyume 2010-11-13
  • 打赏
  • 举报
回复
貌似,经纬度也不是每次都能查询到,用经纬度查询一个城市的天气时,精度相差几分都不行,有的能查到,有的查不到,而且同一个经纬度,在不同的时间里能否查到也不一样。
纠结的木棉花 2010-11-12
  • 打赏
  • 举报
回复
11-12 04:34:30.667: DEBUG/LocaleSetup(732): Update locate list
11-12 04:34:30.692: DEBUG/ResourceType(732): calling getConfigurations
11-12 04:34:30.735: DEBUG/ResourceType(732): called getConfigurations size=118
11-12 04:34:30.737: DEBUG/asset(732): locale 0: ''
11-12 04:34:30.747: DEBUG/asset(732): locale 1: 'ja'
11-12 04:34:30.757: DEBUG/asset(732): locale 2: 'de'
11-12 04:34:30.767: DEBUG/asset(732): locale 3: 'nl'
11-12 04:34:30.767: DEBUG/asset(732): locale 4: 'pl'
11-12 04:34:30.777: DEBUG/asset(732): locale 5: 'ko'
11-12 04:34:30.798: DEBUG/asset(732): locale 6: 'fr'
11-12 04:34:30.798: DEBUG/asset(732): locale 7: 'cs'
11-12 04:34:30.798: DEBUG/asset(732): locale 8: 'es'
11-12 04:34:30.798: DEBUG/asset(732): locale 9: 'it'
11-12 04:34:30.798: DEBUG/asset(732): locale 10: 'ru'
11-12 04:34:30.798: DEBUG/asset(732): locale 11: 'en_GB'
11-12 04:34:30.798: DEBUG/asset(732): locale 12: 'en_SG'
11-12 04:34:30.798: DEBUG/asset(732): locale 13: 'zh_CN'
11-12 04:34:30.798: DEBUG/asset(732): locale 14: 'en_US'
11-12 04:34:30.798: DEBUG/asset(732): locale 15: 'en_AU'
11-12 04:34:30.798: DEBUG/asset(732): locale 16: 'zh_TW'
11-12 04:34:30.798: DEBUG/asset(732): locale 17: 'en_CA'
11-12 04:34:30.798: DEBUG/asset(732): locale 18: 'fr_CA'
11-12 04:34:30.798: DEBUG/asset(732): locale 19: 'nl_BE'
11-12 04:34:30.798: DEBUG/asset(732): locale 20: 'fr_BE'
11-12 04:34:30.798: DEBUG/asset(732): locale 21: 'de_DE'
11-12 04:34:30.798: DEBUG/asset(732): locale 22: 'de_CH'
11-12 04:34:30.798: DEBUG/asset(732): locale 23: 'fr_CH'
11-12 04:34:30.798: DEBUG/asset(732): locale 24: 'it_CH'
11-12 04:34:30.798: DEBUG/asset(732): locale 25: 'de_LI'
11-12 04:34:30.798: DEBUG/asset(732): locale 26: 'nl_NL'
11-12 04:34:30.798: DEBUG/asset(732): locale 27: 'pl_PL'
11-12 04:34:30.798: DEBUG/asset(732): locale 28: 'ja_JP'
11-12 04:34:30.798: DEBUG/asset(732): locale 29: 'fr_FR'
11-12 04:34:30.798: DEBUG/asset(732): locale 30: 'ko_KR'
11-12 04:34:30.817: DEBUG/asset(732): locale 31: 'es_ES'
11-12 04:34:30.817: DEBUG/asset(732): locale 32: 'de_AT'
11-12 04:34:30.817: DEBUG/asset(732): locale 33: 'it_IT'
11-12 04:34:30.817: DEBUG/asset(732): locale 34: 'ru_RU'
11-12 04:34:30.817: DEBUG/asset(732): locale 35: 'cs_CZ'
11-12 04:34:30.817: DEBUG/asset(732): locale 36: 'en_NZ'
11-12 04:34:30.817: DEBUG/asset(732): locale 37: 'en'
11-12 04:34:30.978: DEBUG/LocaleSetup(732): customLocales:
11-12 04:34:31.487: WARN/KeyCharacterMap(732): No keyboard for id 0
11-12 04:34:31.607: WARN/KeyCharacterMap(732): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-12 04:34:31.801: WARN/InputManagerService(571): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@437247b0 (uid=10004 pid=732)
11-12 04:34:31.817: WARN/InputManagerService(571): Client not active, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@436d3418
11-12 04:34:32.148: WARN/ActivityManager(571): Activity pause timeout for HistoryRecord{436bd608 {com.android.customlocale/com.android.customlocale.CustomLocaleActivity}}
11-12 04:34:32.367: WARN/InputManagerService(571): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4371eb60
11-12 04:34:33.797: DEBUG/dalvikvm(622): GC freed 1879 objects / 97256 bytes in 184ms
11-12 04:34:36.517: INFO/ActivityManager(571): Starting activity: Intent { action=android.intent.action.MAIN categories={android.intent.category.LAUNCHER} flags=0x10200000 comp={com.studio.android.chp08.ex01/com.studio.android.chp08.ex01.CurrentLocation} }
11-12 04:34:37.237: DEBUG/GpsLocationProvider(571): setMinTime 2000
11-12 04:34:37.577: WARN/IInputConnectionWrapper(622): showStatusIcon on inactive InputConnection
11-12 04:34:37.807: INFO/ActivityManager(571): Displayed activity com.studio.android.chp08.ex01/.CurrentLocation: 1241 ms
11-12 04:34:42.958: DEBUG/dalvikvm(622): GC freed 147 objects / 6264 bytes in 122ms
打log:




11-12 04:39:31.838: DEBUG/dalvikvm(622): GC freed 227 objects / 10272 bytes in 155ms
11-12 04:39:41.287: WARN/KeyCharacterMap(864): No keyboard for id 0
11-12 04:39:41.307: WARN/KeyCharacterMap(864): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-12 04:39:44.527: WARN/KeyCharacterMap(622): No keyboard for id 0
11-12 04:39:44.538: WARN/KeyCharacterMap(622): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-12 04:39:46.287: INFO/ActivityManager(571): Starting activity: Intent { action=android.intent.action.MAIN categories={android.intent.category.LAUNCHER} flags=0x10200000 comp={com.studio.android.chp08.ex01/com.studio.android.chp08.ex01.CurrentLocation} }
11-12 04:39:46.798: DEBUG/location(864): locationnull
11-12 04:39:46.818: DEBUG/GpsLocationProvider(571): setMinTime 2000
11-12 04:39:47.247: WARN/IInputConnectionWrapper(622): showStatusIcon on inactive InputConnection
11-12 04:39:47.437: INFO/ActivityManager(571): Displayed activity com.studio.android.chp08.ex01/.CurrentLocation: 1120 ms
11-12 04:39:52.638: DEBUG/dalvikvm(622): GC freed 155 objects / 6952 bytes in 170ms
好像检测不到信息
纠结的木棉花 2010-11-12
  • 打赏
  • 举报
回复
我觉得这个是由于google的好多网站都被封了,别的baidu在模拟器上面都能运行,但是google则打不开
凉凉二点凉 2010-11-12
  • 打赏
  • 举报
回复
哦,对了,我的测试环境为moto的里程碑
l896993615 2010-11-12
  • 打赏
  • 举报
回复
应该需要加载GPS模块里面的经纬过来吧,
Sodino 2010-11-12
  • 打赏
  • 举报
回复
http://blog.csdn.net/sodino/archive/2010/10/12/5935307.aspx
不知道上面这东西有帮助没
yihua0001 2010-11-12
  • 打赏
  • 举报
回复
楼主的机器是有GPS模组的吗?

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧