gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:59:22 25 4
gpt4 key购买 nike

在我完成之前我还有很多事情要做,在连续工作了 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com