android - 如何为片段内的 GoogleMap API 提供特定的地图搜索
问题描述
因此,我基本上将 GoogleMaps API 放在我的应用程序的片段中,并且我想给它一个特定的默认搜索,就像我们对 Intent 所做的那样,但在这种情况下,我使用片段而不是意图。`public class LocalGymsFragment extends Fragment {
MapView mMapView;
private GoogleMap googleMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_local_gyms, container, false);
mMapView = (MapView) rootView.findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
mMapView.onResume(); // needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap mMap) {
googleMap = mMap;
// For dropping a marker at a point on the Map
LatLng sydney = new LatLng(-34, 151);
googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker Title").snippet("Marker Description"));
// For zooming automatically to the location of the marker
CameraPosition cameraPosition = new CameraPosition.Builder().target(sydney).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
});
return rootView;
}
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}
}`
解决方案
我建议您尝试在约束布局或新的 GoogleMaps Activity 上实现 GoogleMaps API。这是因为 Fragments 不仅仅是一杯茶。在片段上实现这一点很困难。
推荐阅读
- django - 在单个 url 的一个视图中使用多个视图的输出
- java - 如何在注释和注释之间的空白行上使 checkstyle 失败?
- windows - VMware Host-only 适配器子网不工作
- python - 使用 Python 提取币安期货数据(ETHUSDT 季刊 0625)
- javascript - 在带有 webpack 的浏览器中使用 NodeJS Crypto 模块
- vue.js - 无法将 Vue 路由器设置为历史模式
- powershell - 如果 Get-ADGroupMember 没有找到禁用用户 .. 说
- swiftui - iOS 15 中可搜索功能的访问字符
- ubuntu - 我想问一下elasticsearch和Ubuntu
- node.js - TypeError:无法读取未定义 Flutter 的属性“id”