【发布时间】:2016-05-25 20:47:10
【问题描述】:
我试图在谷歌地图中设置一个标记,方法是在使用这个找到地点后给出某个地方的纬度和经度:
public void findPlace() {
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
.build();
try {
Intent intent =
new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
.setFilter(typeFilter)
.build(getActivity());
getActivity().startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
//to add marker for destination location
} catch (GooglePlayServicesRepairableException e) {
// TODO: Handle the error.
} catch (GooglePlayServicesNotAvailableException e) {
// TODO: Handle the error.
}
}
从这里我得到了这个地方,我正在使用以下内容来获取搜索到的地方的经纬度:
Place place = PlaceAutocomplete.getPlace(MainActivity.this, data);
Log.e("lat and long", place.getLatLng().latitude + place.getLatLng().longitude )
在此之后,我尝试使用我创建的这种方法将标记设置为该纬度和经度:
protected Marker createMarker(double latitude, double longitude) {
Logger.e("inside" ,"create marker");
return mMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.anchor(0.5f, 0.5f)
.title("Destination")
.snippet("Snippet Destination").icon(BitmapDescriptorFactory.fromResource(R.drawable.black)));
}
而且这个方法似乎只在 onverride 方法 onMapReady 中有效。
点击按钮后如何使用?
【问题讨论】:
标签: android google-maps google-maps-markers