2014-02-12 34 views
3

後的位置按鈕,我有地圖片段命名TestMap。當它加載的第一 時,它從方法 setMyLocationButtonEnabled(true)顯示當前位置和位置按鈕。當它第一次加載後 它不顯示當前位置和位置按鈕......... 任何想法爲什麼?地圖不顯示首次啓動片段

TestMap ...

package com.example.map; 

import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.Toast; 

public class TestMap extends Fragment{ 
    public GoogleMap gmap; 
    View view; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    } 

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

     view = inflater.inflate(R.layout.findmap, container, false); 
     initializemap(); 
     gmap.setMyLocationEnabled(true); 
     // gmap.getUiSettings().setMyLocationButtonEnabled(true); 

     return view; 
    } 

    private void initializemap() { 
     // TODO Auto-generated method stub 
     if(gmap == null){ 
      gmap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.mapView)) 
        .getMap(); 
     } 
     if (gmap == null) { 
      Toast.makeText(getActivity(), 
        "Sorry! unable to create maps", Toast.LENGTH_SHORT) 
        .show(); 
     } 
    } 

    public void onResume(){ 
     super.onResume(); 
     // initializemap(); 
    } 

    public void onDestroyView() { 
     super.onDestroyView(); 
     SupportMapFragment f = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.mapView); 
     if (f != null){ 
      getFragmentManager().beginTransaction().remove(f).commitAllowingStateLoss(); 
     } 
    } 

} 

回答

0

setMyLocationButtonEnabled()默認爲true。

 // Show current location  
     gmap.setMyLocationEnabled(true); 
    // Location button 
    //comment this line gmap.getUiSettings().setMyLocationButtonEnabled(true); 
+0

後評論行,問題沒有解決........ – Vishwajeet