1

私は解決策を見つけました。マップがまだ初期化されていない可能性があります。 onResume() のように、ライフサイクルの後半で getMap() を試してください。

私のコードは

 protected void onResume() {
        super.onResume();
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
        if (resultCode == ConnectionResult.SUCCESS){
            Toast.makeText(getApplicationContext(),
                    "isGooglePlayServicesAvailable SUCCESS",
                    Toast.LENGTH_LONG).show();

            if(gMap == null){
                gMap = mMapView.getMap();
                if(gMap != null){
                    gMap.setMyLocationEnabled(true);
                    gMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
                }else{
                    Toast.makeText(getApplicationContext(),
                            "cannot getMap!",
                            Toast.LENGTH_LONG).show();
                }
            }

        }else{
            GooglePlayServicesUtil.getErrorDialog(resultCode, this, RQS_GooglePlayServices);
        }
    }
4

2 に答える 2

0

Edited you have done below step:

Add Play Services Library in project :  
 Eclipse > import > Android > Existing Android code in to workspace  
 Browse you SDK path like ~/android-sdk-linux/extras/google/google_play_services  
 import that project in to workspace  

add above library project in to your project. run in Android Device only not in Emulator

it is simple check below code:

 import android.os.Bundle;  
 import android.support.v4.app.FragmentManager;  
 import com.actionbarsherlock.app.SherlockFragmentActivity;  
 import com.google.android.gms.maps.GoogleMap;  
 import com.google.android.gms.maps.GoogleMap.OnMapClickListener;  
 import com.google.android.gms.maps.SupportMapFragment;  
 import com.google.android.gms.maps.model.LatLng;  
 import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends Activity {  
      private GoogleMap MAP;  
      @Override  
      protected void onCreate(Bundle arg0) {  
           // TODO Auto-generated method stub  
           //setTheme(R.style.Theme_Sherlock);  
           super.onCreate(arg0);  
           setContentView(R.layout.activity_main);  
           FragmentManager myFM = getSupportFragmentManager();  
           SupportMapFragment myMAPF = (SupportMapFragment) myFM  
                     .findFragmentById(R.id.fragment1);  
           MAP = myMAPF.getMap();  
           MAP.setMyLocationEnabled(true);  
           MAP.setMapType(GoogleMap.MAP_TYPE_HYBRID);  
           MAP.setOnMapClickListener(new OnMapClickListener() {  
                @Override  
                public void onMapClick(LatLng point) {  
                     // TODO Auto-generated method stub  
                     MAP.addMarker(new MarkerOptions().position(point).title(  
                               point.toString()));  
                }  
           });  
      }  
 } 

more detail check this : clickhere & clickhere

as per your code check this:

Marker marker = map.add(new MarkerOptions()
           .position(new LatLng(37.7750, 122.4183))
           .title("San Francisco")
           .snippet("Population: 776733"));

   gMap.addMarker(marker);
于 2013-03-01T10:06:01.427 に答える
0

これを試して、カスタム マーカーを追加します。

public void placingCurrentMarkerWithBalloon(String address)
    {
        LatLng current_latlng = new LatLng(cur_lat, cur_lng);
        gMapview.addMarker(new MarkerOptions().position(current_latlng)
                    .title("Address")
                    .snippet(address)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.person_marker))
/*.icon(BitmapDescriptorFactory.defaultMarker())*/
).showInfoWindow();
}
于 2014-06-16T09:44:02.720 に答える