2012-08-16 86 views
0

我有一个文本视图来显示我的经度和纬度,现在的问题是我总是得到这对夫妇(32,35)(这是我认为的某个海洋中的某个地方),我甚至去过出去散步,给全球定位系统一个机会,但我什么都没有。Android获取静态错误的位置

我想看看它是否与我的手机或手机中的GPS有关,所以我继续打开Waze应用程序,看到它实际上工作。

可能是什么问题?

这里是我的简单的代码片段:

public class Main extends Activity implements LocationListener { 
    private LocationManager manager; 
    private TextView tv; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     tv = (TextView) findViewById(R.id.textView1); 
     tv.setText("Hello There"); 
     manager = (LocationManager) this.getSystemService(LOCATION_SERVICE); 
     manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); 

    } 

    @Override 
    public void onLocationChanged(Location location) { 
     tv.setText((int)location.getLatitude()+ ","+ (int)location.getLongitude()); 
    } 
... 
} 
+0

权限被添加? – 2012-08-16 10:20:05

+2

@MMohsinNaeem:他说他在谷歌地图中获得了valus(32,35) – MAC 2012-08-16 10:21:28

回答

1

尝试这种

tv.setText(location.getLatitude()+ ","+location.getLongitude()); 

代替

tv.setText((int)location.getLatitude()+ ","+ (int)location.getLongitude()); 
      ^^^        ^^^ 

,因为你正在转换latitudelongitudeint并在你可能会遇到很小的变化。

32.110 35.500 you will get (32,35) 
32.120 35.540 you will get (32,35) 
32.180 35.580 you will get (32,35) 
32.200 35.900 you will get (32,35) 
32.290 35.880 you will get (32,35) 
    ^^^ ^^^ 
+0

32,35是在太平洋某处:\ – 2012-08-16 10:51:10