Android我在谷歌地图上看不到任何标记
我阅读了教程并实现了所有功能,但当我运行应用程序时,我看不到标记,也不明白为什么。我想添加一个带有位置“PLACE”的标记,我添加了它,但没有显示 我认为问题在于这方面: mMap=MapFragmentgetFragmentManager.findFragmentByIdR.id.map.getMap 因为当我在“MapFragment.newInstance”中添加“mapOptions”时,地图会显示位置“PLACE”,但如果我不添加此选项,地图会显示为正常 有人能帮忙吗?关于英语的事,谢谢,也很抱歉 我的代码: Frag_Map.javaAndroid我在谷歌地图上看不到任何标记,android,google-maps-android-api-2,Android,Google Maps Android Api 2,我阅读了教程并实现了所有功能,但当我运行应用程序时,我看不到标记,也不明白为什么。我想添加一个带有位置“PLACE”的标记,我添加了它,但没有显示 我认为问题在于这方面: mMap=MapFragmentgetFragmentManager.findFragmentByIdR.id.map.getMap 因为当我在“MapFragment.newInstance”中添加“mapOptions”时,地图会显示位置“PLACE”,但如果我不添加此选项,地图会显示为正常 有人能帮忙吗?关于英语的事,谢
public class Frag_Map extends Activity {
private GoogleMap mMap;
private static final LatLng PLACE = new LatLng(38.977,-9.4185);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xmlfile);
MapFragment mMapFragment = MapFragment.newInstance(mapOptions());
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.map, mMapFragment);
fragmentTransaction.commit();
setUpMapIfNeeded();
}
private GoogleMapOptions mapOptions()
{
GoogleMapOptions options = new GoogleMapOptions();
options.mapType(GoogleMap.MAP_TYPE_HYBRID)
.compassEnabled(true)
.rotateGesturesEnabled(true)
.scrollGesturesEnabled(true)
.tiltGesturesEnabled(true)
.zoomGesturesEnabled(true)
.zoomControlsEnabled(true);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(PLACE)
.zoom((float) 17.5)
.build();
options.camera(cameraPosition);
return options;
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
// The Map is verified. It is now safe to manipulate the map.
mMap.addMarker(new MarkerOptions()
.position(new LatLng(38.977,-9.4185))
.title("Hello world")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.mapaovelay1))
.visible(true));
}
}
}
xmlfile.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
尝试在添加标记后添加此代码
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(38.977,-9.4185), 15));
// Zoom in, animating the camera.
mMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
希望这会将您带到标记位置地图是否显示在您的应用程序中?为什么您两次调用addMarker方法,一次使用图标功能,另一次使用相同的图标?是的,地图显示在我的应用程序中,选项正确,但没有标记现在我调用addMarker一次,谢谢,但是没有看到标记谢谢,我添加了您的代码,但没有看到标记,我认为问题出在这行:mMap=MapFragment getFragmentManager.findFragmentByIdR.id.map.getMap;因为当我在“MapFragment.newInstance”中添加“mapOptions”时,地图显示位置为“PLACE”,但如果我不添加此选项,地图显示为正常。谢谢,我解决了问题,问题是我创建了一个新地图,使用以下行:MapFragment mMapFragment=MapFragment.newInstancemapOptions;当我调用getMap时,出现的映射是一个MapFragment。