Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Google map run on real device it will not run on emulator so try in real device if it will not run on real device then try this code and you also properly check that you add googleplay library in your project properties</p> <pre><code>public class MainActivity extends Activity implements LocationListener{ LocationManager locationManager; private GoogleMap googleMap; double latitude=17.385044; double longitude=78.486671; private String provider; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LocationManager service=(LocationManager)getSystemService(LOCATION_SERVICE); boolean enableGPS= service.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean enableWifi=service.isProviderEnabled(LocationManager.NETWORK_PROVIDER); // Check if enabled and if not send user to the GSP settings // Better solution would be to display a dialog and suggesting to // go to the settings if(!enableGPS){ Toast.makeText(getApplicationContext(),"Gps signal not found",1).show(); Intent intent=new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, false); Location location = locationManager.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { Toast.makeText(this, "Selected Provider " + provider, Toast.LENGTH_SHORT).show(); onLocationChanged(location); } else { //do something } try { //loading map initilizeMap(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } private void initilizeMap(){ if(googleMap==null){ googleMap=(MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap(); //check if map is created succesfully or not if(googleMap==null){ Toast.makeText(getApplicationContext(),"sorry unable to create map",0).show(); } } </code></pre> <p>MarkerOptions markerOptions=new MarkerOptions().position(new LatLng(latitude, longitude)); markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)); CameraPosition cameraPosition=new CameraPosition.Builder().target(new LatLng(17.385044, 78.486671)).zoom(12).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); googleMap.setMyLocationEnabled(true); googleMap.setOnInfoWindowClickListener(null); }</p> <pre><code> @Override protected void onResume(){ super.onResume(); initilizeMap(); } /* Remove the locationlistener updates when Activity is paused */ @Override protected void onPause() { super.onPause(); locationManager.removeUpdates(this); } public void onLocationChanged(Location location) { double lat = location.getLatitude(); double lng = location.getLongitude(); Toast.makeText(this, "Location " + lat+","+lng, Toast.LENGTH_LONG).show(); LatLng coordinate = new LatLng(lat, lng); Toast.makeText(this, "Location " + coordinate.latitude+","+coordinate.longitude, Toast.LENGTH_LONG).show(); Marker startPerc = googleMap.addMarker(new MarkerOptions() .position(coordinate) .title("Start") .snippet("Inizio del percorso") .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))); } public void onProviderDisabled(String provider) { Toast.makeText(this, "Enabled new provider " + provider, Toast.LENGTH_SHORT).show(); } public void onProviderEnabled(String provider) { Toast.makeText(this, "Disabled provider " + provider, Toast.LENGTH_SHORT).show(); } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload