I found a solution . The map may not have been initialized yet, try getMap() in a later point of the lifecycle, like onResume()
My code is
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);
}
}
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);
Try this to add custom marker:
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();
}