【发布时间】:2013-01-15 08:30:21
【问题描述】:
我想开发一个应用程序,如果我打开该应用程序,它将显示我设备的当前位置。 我想在不使用 gps 的情况下做到这一点。我已经为它写了一个代码。但它会在打开地图时显示美国的位置。我希望它显示我当前的位置(即印度浦那)。 如何获得我的大致正确位置?
这是我的代码
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
setContentView(R.layout.main);
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener locListener = new LocationListener(){
public void onLocationChanged(Location loc)
{
loc.getLatitude();
loc.getLongitude();
String Text = "My current location is: " +
"Latitud = " + loc.getLatitude() +
"Longitud = " + loc.getLongitude();
Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
}
【问题讨论】:
-
我已在清单文件中添加了所有必需的权限,例如 Internet、粗略和精细位置