安卓和 map v2 : how do I get the users location?

标签 android android-maps

在我完成之前我还有很多事情要做,在连续工作了 8 个小时之后我需要寻求帮助。我已经设法在 Android 上设置 V2 map ,它们可以在我的设备上运行,我不知道在哪里可以找到可以帮助我将其构建为更高级 map 应用程序的资源,我什至无法显示用户位置。我在有互联网的 Android 手机上调试。我已经阅读了 10 多个有关 Stack overflow 的问题,并阅读了 Google 上的一些文档。

到目前为止,这是我的类(class):

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class MainActivity extends FragmentActivity  {


  private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     setUpMapIfNeeded();

}

  @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }



  private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }


  private void setUpMap() {

      mMap.setMyLocationEnabled(true);
      mMap.getMyLocation();



    }
}

我需要构建以获取用户位置,然后允许用户搜索地点并存储它们,有人认为这在 V2 map 中可行吗?

非常感谢!

最佳答案

I need to build up to getting the users location, then allowing the user to search for places and store them, does anyone think this would be possible in V2 maps?

您需要通过 LocationManager 找到用户的位置,就像在任何 Android 应用程序中一样。或者,您可以通过调用 setLocationSource() 将这些位置提供给 Maps V2在你的 GoogleMap .

更新

如果您使用 setMyLocationEnabled(true)GoogleMap ,您可以通过 getMyLocation() 检索位置在 GoogleMap .这比滚动您自己的位置跟踪更简单,但您没有那么多的控制权(例如,您不知道移动情况)。

关于安卓和 map v2 : how do I get the users location?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14025014/

相关文章:

android - 在 MapView 被触及之前 View 不会更新

Android 谷歌地图 API v2 : Authorization failure at different laptops

android gps定位精度圈

java - 如何将类返回到 onPostExecute?

java - Android android.R.id.list ListView fragment 异常

android - 使用通用 FindViewById 是一种不好的做法吗?

java - 尝试对空对象引用调用虚拟方法 SupportMapFragment getMapAsync

android - 谷歌地图 - 按类型标记聚类

java - MapView 上的多边形数组

java - onCharacteristicwrite 中的 Android 蓝牙状态 133