-1
A
回答
0
将其添加到XML中。
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
,并尝试使用该Java中的文件
private GoogleMap map;
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
// map.
if (map == null) {
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
map.setMyLocationEnabled(true);
map.getUiSettings().setMyLocationButtonEnabled(false);
map.getUiSettings().setZoomControlsEnabled(false);
map.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location loc) {
}
});
}
}
使用此方法从API创建多个标记。
protected void createMarker(double latitude, double longitude, Bitmap iconResID) {
map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
/* .icon(BitmapDescriptorFactory
.fromResource(R.drawable.pin_client_org))*/
.icon(BitmapDescriptorFactory.fromBitmap(iconResID)));
/* .title(title)
.anchor(0.5f, 0.5f)
.snippet(snippet)*/
}
相关问题
- 1. android gps如何显示当前位置
- 2. 使用片段我想要在Android中获取当前位置
- 3. 我想要显示基于位置的信息时,使用android
- 4. 如何显示从我当前位置附近的宿舍android
- 5. 如何显示多个用户在谷歌地图上的当前位置android
- 6. 显示当前用户位置?
- 7. 显示MKMapView以一次显示多个注释和当前用户位置
- 8. 显示我的NodeJs应用程序的当前npm版本
- 9. 在Google地图上显示当前位置附近的多个位置
- 10. 在android中启用GPS后显示当前位置
- 11. 使用CEF,bing地图在显示路线之前先显示当前位置
- 12. 我想跟踪我在Android应用程序中的当前位置
- 13. 在Android版本6.0中未获取当前位置
- 14. rails在页面上显示我的代码的当前版本
- 15. MKMapview显示当前位置错误
- 16. 想要在android活动中获得用户的当前位置
- 17. 当前位置的Android
- 18. 如何显示Android Google地图中的当前位置?
- 19. 在Android屏幕的上半部分显示当前位置
- 20. 方向不显示我的当前位置和目的地
- 21. 在Android的谷歌地图上显示当前位置和其他位置
- 22. 如何使用MKMapView显示从当前位置到neares位置的方向
- 23. 我使用此代码来查看用户当前位置。当前位置
- 24. 在Google Map中显示我的当前位置
- 25. 谷歌地图不显示我的当前位置
- 26. Android Market不显示我的新版本
- 27. {Android App}我如何显示距离当前位置和指定点的距离?
- 28. Android:在地图上显示和移动当前位置
- 29. 如何在android mapview中精确显示当前位置?
- 30. 如何在Android中显示谷歌当前位置图标?
谢谢。但是。 ..仍然错误此行:无法解析方法getMap()map =((SupportMapFragment)getSupportFragmentManager()。findFragmentById(R.id.map))。getMap(); –