相关疑难解决方法(0)

在Android上获取用户当前位置的最简单,最强大的方法是什么?

LocationManagerAndroid上的API似乎对于仅需要偶尔粗略估计用户位置的应用程序来说有点痛苦.

我正在处理的应用程序本身并不是一个位置应用程序,但它确实需要获取用户的位置才能显示附近的商家列表.它不需要担心用户是否在移动或类似的东西.

这是我想做的事情:

  1. 向用户显示附近位置的列表.
  2. 预加载用户的位置,以便在ActivityX中需要它时,它将可用.
  3. 我并不特别关心更新的准确性或频率.只要没有办法,抓住一个位置就足够了.也许如果我想要花哨,我会每隔几分钟更新一次位置,但这不是一个重要的优先事项.
  4. 只要有GPS或网络位置提供商,就可以使用任何设备.

看起来它应该不那么难,但在我看来,我必须启动两个不同的位置提供商(GPS和NETWORK)并管理每个生命周期.不仅如此,我还必须在多个活动中复制相同的代码以满足#2.我曾尝试过使用getBestProvider()过去将解决方案缩减为只使用一个位置提供商,但这似乎只能为您提供最好的"理论"提供商,而不是实际上会给您带来最佳结果的提供商.

有没有更简单的方法来实现这一目标?

android location geolocation latitude-longitude

788
推荐指数
12
解决办法
31万
查看次数

如何在Android中以编程方式获取当前GPS位置?

我需要以编程方式使用GPS获取当前位置.我怎样才能实现它?

gps android location geolocation

694
推荐指数
17
解决办法
86万
查看次数

Android - 如何获取当前位置(经度和纬度)?

我使用以下代码来获取当前位置即(纬度和经度),但我没有获得当前位置(纬度和经度).

谁知道为什么?

package com.ram.currentlocation;

import android.app.Activity;    
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

public class Location_Gps extends Activity
{

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      /* Use the LocationManager class to obtain GPS locations */
      LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

      LocationListener mlocListener = new MyLocationListener();
      mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
    }

    /* Class My Location Listener */
    public class MyLocationListener implements LocationListener
    {

      @Override
      public …
Run Code Online (Sandbox Code Playgroud)

android geolocation latitude-longitude google-latitude geocode

17
推荐指数
2
解决办法
7万
查看次数