2017-08-09 26 views
0

這是我用來繪製My Map上的點的Java代碼,這些代碼包含在我的Home Home Fragment XML中,這些代碼也在下面,當我運行應用程序時,Map顯示得很好,我也設置了縮放不工作,是否有我的代碼中缺少的東西。由於我想在地圖上繪製一些點,但是當我運行我的應用程序時它們不顯示?

import android.app.Fragment; 
import android.os.Build; 
import android.os.Bundle; 
import android.support.annotation.Nullable; 
import android.support.annotation.RequiresApi; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapView; 
import com.google.android.gms.maps.MapsInitializer; 
import com.google.android.gms.maps.OnMapReadyCallback; 
import com.google.android.gms.maps.model.CameraPosition; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

/** 
* Created by Aids on 09/08/2017. 
*/ 

public class Map_Code_Home extends Fragment implements OnMapReadyCallback { 

    GoogleMap mGoogleMap; 
    MapView mMapView; 
    View mView; 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 

     mView = inflater.inflate(R.layout.fragment_home, container, false); 
     return mView; 

    } 

    @Override 
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
     super.onViewCreated(view, savedInstanceState); 

     mMapView = (MapView) mView.findViewById(R.id.map); 
     if(mMapView != null){ 
      mMapView.onCreate(null); 
      mMapView.onResume(); 
      mMapView.getMapAsync(this); 
     } 
    } 

    @RequiresApi(api = Build.VERSION_CODES.M) 
    @Override 
    public void onMapReady(GoogleMap googleMap) { 

     MapsInitializer.initialize(getContext()); 
     mGoogleMap = googleMap; 
     googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 

     googleMap.addMarker(new MarkerOptions().position(new LatLng(48.689247, -74.044502)).title("Statue of Liberty")); 

     CameraPosition SettingCamera = CameraPosition.builder().target(new LatLng(48.689247, -74.044502)).zoom(40).build(); 
     googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(SettingCamera)); 

    } 
} 

下面是我的地圖碎片,我有我的HomeFragment XML佈局文件。

<fragment 
      android:id="@+id/map" 
      class="com.google.android.gms.maps.SupportMapFragment" 
      android:layout_width="fill_parent" 
      android:layout_height="275dp" 
      android:layout_below="@id/textView3"/> 
+0

你應該有戶口本:縮放比例範圍0 - 19 –

+0

改變了它到14.仍然沒有出現 –

回答

0

試圖刪除這個註解

@RequiresApi(api = Build.VERSION_CODES.M)

,改變moveCamera爲animateCamera

googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(SettingCamera));

相關問題