【问题标题】:How to find and store my device location to my sql db?如何查找我的设备位置并将其存储到我的 sql db?
【发布时间】:2014-10-17 04:59:45
【问题描述】:

我已使用以下代码获取我的设备位置。有没有更好的方法来获取确切地址或谷歌地图的位置,我想将位置存储在我的数据库中MySQL

public class Finder extends Activity implements LocationListener{
    protected LocationManager locationManager;
    protected LocationListener locationListener;
    protected Context context;
    TextView txtLat;
    String lat;
    String provider;
    protected String latitude,longitude; 
    protected boolean gps_enabled,network_enabled;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    txtLat = (TextView) findViewById(R.id.textview1);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    }
    @Override
    public void onLocationChanged(Location location) {
    txtLat = (TextView) findViewById(R.id.textview1);
    txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());
    }

    @Override
    public void onProviderDisabled(String provider) {
    Log.d("Latitude","disable");
    }

    @Override
    public void onProviderEnabled(String provider) {
    Log.d("Latitude","enable");
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    Log.d("Latitude","status");
    }

【问题讨论】:

  • 您似乎想使用 Google Maps API 来做您想做的事。
  • 抱歉,我不知道 Google Maps API。我的基本想法是获取设备的确切位置,但我对仅获取经度和纬度值不满意,因为我还必须将位置存储在我的数据库中
  • 在数据库中保存位置详细信息后你会做什么?
  • 您可以使用 Google Maps API 发送位置,并取回各种信息(包括“英文”位置信息,例如地址等)。去 Google 并检查这些信息。跨度>
  • 对不起桑迪普先生,我不能提供这些细节

标签: java android mysql google-maps


【解决方案1】:

您可以使用Google Geocoder 类检查您当前的地址。根据您的纬度和经度值,您将获得附近地址的列表。您可以选择只接收第一个结果,这可能是您想要的结果。

查看官方文档here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-04
    • 2021-06-01
    • 1970-01-01
    • 2013-08-14
    相关资源
    最近更新 更多