我閱讀教程Google Maps V2並實現所有,但是當我運行應用程序時,我看不到標記,我不明白爲什麼。我想添加一個位置爲'PLACE'的標記,然後添加它,但不顯示。Android我沒有看到谷歌地圖中的標記
我認爲這個問題是在這一行:
mMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
因爲當我加入「MapFragment.newInstance」地圖顯示位置「地」,但是如果我不「的MapOptions()」不添加此選項,地圖顯示正常。
有人可以幫忙嗎?謝謝你,並對英語感到抱歉。
我代碼:
Frag_Map.java
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"/>
是地圖顯示在你的應用程序中嗎? – TheFlash
爲什麼你調用addMarker()方法兩次,一次使用圖標功能,另一次沒有使用相同LatLng的圖標? –
是,地圖顯示在我的應用程序,以正確的選項,但沒有 – nss