【发布时间】:2017-10-14 21:29:55
【问题描述】:
我在Google map 中创建并添加了一个标记,现在我将用户位置作为输入,并根据用户位置,我想添加另一个标记并在其间画一条线。
这就是我所做的。
//OnCreate()
mClient= new GoogleApiClient.Builder(this).
addConnectionCallbacks(this).
addOnConnectionFailedListener(this).
addApi(Places.GEO_DATA_API).enableAutoManage(this, this).build();
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
/**
*
* @PLACES API
*/
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
Log.i("Place Name", "Place: " + place.getName());
LatLng latLng = place.getLatLng();
destinationLat= latLng.latitude;
destinationLng= latLng.longitude;
destinationLatLng= new LatLng(destinationLat, destinationLng);
/* mapFragment.addMarker(new MarkerOptions().position(destinationLatLng)
.title("PAF-KIET"));*/
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i("Error", "An error occurred: " + status);
}
});
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng pafKietLocation = new LatLng(24.865498, 67.073302);
googleMap.addMarker(new MarkerOptions().position(pafKietLocation)
.title("University"));
googleMap.setMinZoomPreference(14.0f);
googleMap.setMaxZoomPreference(74.0f);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(pafKietLocation));
}
问题是我无法找到将用户LatLng 传递到地图的任何方式。
【问题讨论】:
-
“用户LatLng”,你是什么意思?
-
@GurgenHakobyan :在
onMapReady上,我正在添加一个带有预定义Lat Lng值的标记,现在我也想在onPlaceSelected()上添加一个制造商。
标签: android google-maps android-layout android-fragments google-api