0

下面是我的代码,它给出了用户的硬编码 lat long 我想显示动态 latlong 用户去哪里地图显示用户的当前位置怎么做?

       protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_support_map_fragment);


    FragmentManager fmanager = getSupportFragmentManager();
    Fragment fragment = fmanager.findFragmentById(R.id.map);
 SupportMapFragment supportmapfragment = (SupportMapFragment)fragment;
   GoogleMap supportMap = supportmapfragment.getMap();



   LatLng latLng = new LatLng(24.89337, 67.02806);
   supportMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
   supportMap.addMarker(new MarkerOptions()
           .position(latLng)
           .title("My Spot")
           .snippet("This is my new spot!")

 .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
   supportMap.getUiSettings().setCompassEnabled(true);
   supportMap.getUiSettings().setZoomControlsEnabled(true);
   supportMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 20));



}
4

2 回答 2

1

尝试添加这一行:

supportMap.setMyLocationEnabled(true);
于 2013-11-07T00:15:25.143 回答
0

您显然需要获取用户的当前位置。您需要使用LocationListener来请求持续更新。您可以指定位置更新之间的时间间隔或距离间隔。这为您提供了一个Location对象,您可以从中提取纬度和经度。然后,您可以使用这 2 个值来指示地图上的当前位置。关于如何获取当前位置有很多问题和很好的答案。你可以从阅读开始:

位置策略 Google 的文档

之前的一些问题是:

希望这可以帮助。

于 2013-11-07T00:15:24.297 回答