Android getLastKnownLocation()获取当前位置


用Google map api开发是一件令人纠结的事情,使用 getLastKnownLocation() 总是莫名奇妙的获取不到值,为null,然后又莫名其妙的好了。调试了半天也没用,上网找资料,千篇一律的一个答案。

所以以后就让它自生自灭吧。

  1. LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);           
  2. Criteria criteria = new Criteria();  
  3. criteria.setAccuracy(Criteria.ACCURACY_FINE);  
  4. String provider = locationManager.getBestProvider(criteria, true);  
  5. locationManager.requestLocationUpdates(provider, 20000this);   
 
  1. mostRecentLocation = locationManager.getLastKnownLocation(provider);  

就这6句也不用多写!

同时获取的当前位置也不准确,不知道人家google自己怎么用的,是我修炼不够吗?

说到底还是js网页开发吧,干嘛还要撤到Android Java上去呢?

我的思路有时候还是对的 ,就是对细节把握不行,而且对莫名奇妙的bug莫名其妙的烦躁,一点解决的耐心都没有。

这都是问题!

相关内容