【发布时间】:2015-01-03 03:27:24
【问题描述】:
我已经在 android 中集成了谷歌地图。我正在使用 GPS 获取当前位置。在 Onlocationchanged 上,我正在更新当前位置。
我怀疑我在 Google 地图 UI 上。我想从我当前的位置作为起点步行或开车,我想开始在地图上动态地画线。
我在网上搜索了很长时间,但我没有得到任何解决方案。这是我的代码,请任何人帮助我解决这个问题。
private void initalizeMap()
{
// Google Play Services are available
// Getting GoogleMap object from the fragment
googleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();
if(gps.canGetLocation())
{
double latitude = Double.valueOf(Helper.loadSavedPreferences(getActivity(), NameConversion.LATITUDE));
double longtitude = Double.valueOf(Helper.loadSavedPreferences(getActivity(), NameConversion.LONGITUDE));
Log.d("getting gps value", ""+ latitude);
Log.d("getting gps Long", ""+ longtitude);
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longtitude);
// create marker
marker = new MarkerOptions().position(latLng).title("You are here!");
// Changing marker icon
// set yours icon here
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_green_point));
// Showing the current location in Google Map
googleMap.setTrafficEnabled(true);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(25));
googleMap.addMarker(marker);
}else{
Toast.makeText(getActivity(), "failed To get the location", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onLocationChanged(Location location) {
double latitude = gps.getLatitude();
// Getting longitude of the current location
double longitude = gps.getLongitude();
// Creating a LatLng object for the current location
Log.d("latitude map Class", "latitude: " + gps.getLatitude());
Log.d("longitude Map CLass", "longitude: " + gps.getLongitude());
LatLng latLng = new LatLng(latitude, longitude);
// create marker
MarkerOptions marker = new MarkerOptions().position(latLng).title("You are here!");
// Changing marker icon
// set yours icon here
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_green_point));
// Showing the current location in Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(25));
}
我尝试使用以下链接 [1 st lnikn second link
【问题讨论】:
标签: android google-maps