我在使用Android定位系统的NETWORK提供商获取当前位置坐标时遇到了麻烦.
已经阅读了很多教程,并为我的项目实现了4或5个现有的类,所有这些都给了我最后的坐标但不是当前的坐标.
我很确定问题是我缺少的基本问题,但我无法理解究竟是什么.
我现在使用的代码:
这是我的主要活动
package com.example.locationtests;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GPSTracker mGPS = new GPSTracker(this);
TextView text = (TextView) findViewById(R.id.texts);
if(mGPS.canGetLocation ){
mGPS.getLocation();
text.setText("Lat"+mGPS.getLatitude()+"Lon"+mGPS.getLongitude());
}else{
text.setText("Unabletofind");
System.out.println("Unable");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我用于跟踪的课程:
package com.example.locationtests;
import android.app.AlertDialog; …Run Code Online (Sandbox Code Playgroud)