Здесь
mMap.addMarker(new MarkerOptions().position(new LatLng(22.7253, 75.8655)).title("Indore"));
Приведенный выше код строки показывает маркер на карте Google, но
mMap.addMarker(new MarkerOptions().position(new LatLng(mlastLocation.getLongitude(),mlastLocation.getLatitude())));
Почему приведенный выше код строки не показывает маркер на карте Google,
pickuplocation = new LatLng(mlastLocation.getLongitude(),mlastLocation.getLatitude() ); mMap.addMarker(new MarkerOptions().position(pickuplocation).title("Pickup here").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))); mMap.addMarker(new MarkerOptions().position(new LatLng(mlastLocation.getLongitude(),mlastLocation.getLatitude()))); mMap.addMarker(new MarkerOptions().position(new LatLng(22.7253, 75.8655)).title("Indore")); Toast.makeText(getApplicationContext(),""+pickuplocation,Toast.LENGTH_SHORT).show(); cabbook.setText("Getting Your Driver");
Здесь полный код
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{ private GoogleMap mMap; Button logoutBtn,cabbook; FirebaseAuth fAuth; Location mlastLocation; Marker mycurrentmarker; GoogleApiClient mGoogleApiClient; LocationRequest mLocationRequest; FusedLocationProviderClient fusedLocationProviderClient; FirebaseAuth mAuth; FirebaseFirestore mFirebaseFirestore; private LatLng pickuplocation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); logoutBtn = findViewById(R.id.logout); cabbook = findViewById(R.id.cabbook); } @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } mMap = googleMap; mMap.setMyLocationEnabled(true); buildGoogleApiClient(); } public void Logout(View view) { fAuth.signOut(); startActivity(new Intent(getApplicationContext(),login.class)); } public void main(View view) { startActivity(new Intent(getApplicationContext(),login.class)); } protected synchronized void buildGoogleApiClient() { mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API).build(); mGoogleApiClient.connect(); } @Override public void onLocationChanged(Location location) { if(getApplicationContext() !=null) { mlastLocation = location; LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); mMap.animateCamera(CameraUpdateFactory.zoomTo(11)); } } public void customer_request (View view) { String Uid = FirebaseAuth.getInstance().getCurrentUser().getUid(); FirebaseFirestore mdb = FirebaseFirestore.getInstance(); DatabaseReference ref = FirebaseDatabase.getInstance().getReference("customer_request"); GeoFire geoFire = new GeoFire(ref); geoFire.setLocation(Uid,new GeoLocation(mlastLocation.getLongitude(),mlastLocation.getLatitude())); pickuplocation = new LatLng(mlastLocation.getLongitude(),mlastLocation.getLatitude() ); mMap.addMarker(new MarkerOptions().position(pickuplocation).title("Pickup here").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))); mMap.addMarker(new MarkerOptions().position(new LatLng(mlastLocation.getLongitude(),mlastLocation.getLatitude()))); mMap.addMarker(new MarkerOptions().position(new LatLng(22.7253, 75.8655)).title("Indore")); Toast.makeText(getApplicationContext(),""+pickuplocation,Toast.LENGTH_SHORT).show(); cabbook.setText("Getting Your Driver"); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { Toast.makeText(getApplicationContext(), "Provider status changed",Toast.LENGTH_LONG).show(); } @Override public void onProviderEnabled(String provider) { System.out.println("==onProviderEnabled=" + provider); Toast.makeText(getApplicationContext(), "Provider enabled by the user. GPS turned on",Toast.LENGTH_LONG).show(); } @Override public void onProviderDisabled(String provider) { Toast.makeText(getApplicationContext(),"Provider disabled by the user. GPS turned off",Toast.LENGTH_LONG).show(); } @Override public void onPointerCaptureChanged(boolean hasCapture) { } @Override public void onConnected(@Nullable Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setInterval(1000); mLocationRequest.setFastestInterval(1000); mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Log.i("ViewMap", "GPS can work now"); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, this); } @Override public void onConnectionSuspended(int i) { } @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { Log.e("ViewMap", "Google play connection failed. GPS might not work"); }