首页 新闻 会员 周边 捐助

关于android获取位置信息时返回null的问题

0
[已关闭问题] 关闭于 2016-12-07 11:03

代码如下,获取位置信息时总是返回null,不知道什么原因,哪位大侠帮我看看

 1 package polly.liu;
 2 
 3 import java.util.List;
 4 
 5 import org.apache.http.client.methods.HttpGet;
 6 
 7 import android.app.Activity;
 8 import android.app.AlertDialog;
 9 import android.content.Context;
10 import android.content.Intent;
11 import android.os.Bundle;
12 import android.widget.EditText;
13 import android.location.Location;
14 import android.location.LocationManager;
15 
16 public class TestPollyActivity extends Activity {
17     /** Called when the activity is first created. */
18     @Override
19     public void onCreate(Bundle savedInstanceState) {
20         super.onCreate(savedInstanceState);
21         setContentView(R.layout.main);
22         LocationManager locMgr = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
23         Location loc = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
24         //List<String> providerList = locMgr.getAllProviders();
25         //EditText positionText = (EditText)this.findViewById(R.id.editPosition);
26         new AlertDialog.Builder(this).setTitle(String.valueOf(loc)).setView(new EditText(this)).setPositiveButton("留名", null).setNegativeButton("取消", null).show();       
27     }
28 }
微澜的主页 微澜 | 初学一级 | 园豆:-1
提问于:2013-01-26 09:35
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册