什么telephonyManager.getCellLocation()方法返回[英] What telephonyManager.getCellLocation() method return

本文是小编为大家收集整理的关于什么telephonyManager.getCellLocation()方法返回的处理方法,想解了什么telephonyManager.getCellLocation()方法返回的问题怎么解决?什么telephonyManager.getCellLocation()方法返回问题的解决办法?什么telephonyManager.getCellLocation()方法返回问题的解决方案?那么可以参考本文帮助大家快速定位并解决问题,译文如有不准确的地方,大家可以切到English参考源文内容。

问题描述

我使用telephonyManager.getCellLocation(),我得到了[-1,-1,0]的结果,但我无法从输出中理解. 这是任何类型的位置代码,因为我不认为它是一种任何位置的拉特郎. 提前谢谢任何帮助

推荐答案

您可以使用LocationManager.network_Provider而不是LocationManager.gps_provider找到位置. Network_Provider将在可用的GSM或WiFi上解析.显然与WiFi Off,GSM将被使用.请记住,使用细胞网络准确到基本上为500米.

http://developer.android.com/guide/主题/位置/获取 - 用户位置.HTML 有一些非常棒的信息和示例代码.

在使用OnCreate()中的大多数代码完成后,添加以下内容:

// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
  // Called when a new location is found by the network location provider.
  makeUseOfNewLocation(location);
}

public void onStatusChanged(String provider, int status, Bundle extras) {}

public void onProviderEnabled(String provider) {}

public void onProviderDisabled(String provider) {}
 };

  // Register the listener with the Location Manager to receive location updates
  locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

您还可以使您的活动实现LocationListener类,从而在您的活动中实现OnlecationChanged(). 或者你可以使用这个教程获取lat和郎.

本文地址:https://www.itbaoku.cn/post/2277554.html

问题描述

I use telephonyManager.getCellLocation() and i get the result which is [-1,-1,0] but i can't understand from the output. Is this any type of location code because i don't think that it is a kind of lat lang of any position. advance thanks for any help

推荐答案

You can get locating the position using the LocationManager.NETWORK_PROVIDER instead of LocationManager.GPS_PROVIDER. The NETWORK_PROVIDER will resolve on the GSM or wifi, which ever available. Obviously with wifi off, GSM will be used. Keep in mind that using the cell network is accurate to basically 500m.

http://developer.android.com/guide/topics/location/obtaining-user-location.html has some really great information and sample code.

After you get done with most of the code in OnCreate(), add this:

// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
  // Called when a new location is found by the network location provider.
  makeUseOfNewLocation(location);
}

public void onStatusChanged(String provider, int status, Bundle extras) {}

public void onProviderEnabled(String provider) {}

public void onProviderDisabled(String provider) {}
 };

  // Register the listener with the Location Manager to receive location updates
  locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

You could also have your activity implement the LocationListener class and thus implement onLocationChanged() in your activity. or you can use this tutorial to get lat and lang.

查看更多