Get Device Location - [Android Google Maps Course]

  Рет қаралды 141,041

CodingWithMitch

CodingWithMitch

Күн бұрын

Пікірлер: 232
@shahzebmushtaq1297
@shahzebmushtaq1297 4 жыл бұрын
best android developer ever . Big fan... keep it up bro
@cforge2411
@cforge2411 6 жыл бұрын
i finished it just now, and YOU LITERALLY DE-MYSTIFIED the maps. thanks a lot Mitch
@JasonPurkiss
@JasonPurkiss 7 жыл бұрын
I felt sorry for you with your previous video comment of having a broken keybored so have purchased your SQLlite course to help you in these hard times :)
@JasonPurkiss
@JasonPurkiss 7 жыл бұрын
Interestingly the cost of your video's converted to English pounds comes to the price of a beer here in London, so enjoy :)
@codingwithmitch
@codingwithmitch 5 жыл бұрын
hahaha I just saw this now. Thanks Jason.
@tomislavemilov2247
@tomislavemilov2247 5 жыл бұрын
So for the ones that say that they don't get location. This is happening, bacause in this video is used getLastLocation and that's the point of the fusedLocationClient, to use last known location, but in case that the divece is new or was restored to factory reset or there was not call for location from other app it will produce null. So just make a call to get the location and it will work. Great video btw :)
@aymanatef3014
@aymanatef3014 5 жыл бұрын
i used locationManager and work fine too private void getLocalDevice() { LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); try { moveCamera(locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER), DEFAULT_CAMRA_ZOOM, "my place"); } catch (SecurityException e) { Log.d(TAG, "getLocalDevice: " + e.getMessage()); } }
@subodhrai7500
@subodhrai7500 5 жыл бұрын
I want to be a programmer like u, sir, perfect sir, thanx for your uploading such a video its very helpful for me.
@casaurabhkhatri8545
@casaurabhkhatri8545 6 жыл бұрын
You are Hero!!!!!! Explanation is brilliant!! Keep going.
@whogashaga
@whogashaga 5 жыл бұрын
Your course really help me a lot ! thanks
@udgardixit614
@udgardixit614 5 жыл бұрын
Hey how do i ask for the user to turn on device location like the one Google Maps asks when you open it up and haven't turned on your device location..."To continue, turn on device location, which uses Google's location service."
@mimrankhan9974
@mimrankhan9974 6 жыл бұрын
its so simple but i dont know why you make it so difficult you are good programmer
@codingwithmitch
@codingwithmitch 6 жыл бұрын
what lol
@gabrielalmeida1386
@gabrielalmeida1386 6 жыл бұрын
we have a problem, the Play Store is asking for versions with the API 27+, but when I put it to compile for this API the code: "mMap.setMyLocation (true)" causes the application to crash. how to solve?
@hoseaochieng5355
@hoseaochieng5355 6 жыл бұрын
You are such a gem! This is incredibly resourceful to me, gracias!
@cforge2411
@cforge2411 6 жыл бұрын
just wow man thanks. if anyone haad any troubles, now dependencies are added in modules so //Play Services //Maps implementation 'com.google.android.gms:play-services-maps:15.0.1' //Play Services //Location implementation 'com.google.android.gms:play-services-location:15.0.1'
@stonks9755
@stonks9755 5 жыл бұрын
after i added all the additional methods in this tutorial, the map doesnt even show, but the notification "Map is ready" appears. Is there a file that im missing? Or does it have anything to do with the Google API key?
@OneSpikedDrink
@OneSpikedDrink 4 жыл бұрын
Please tell me you found the fix. I have the same issue
@MuhammadBilal-ry5rb
@MuhammadBilal-ry5rb 5 жыл бұрын
"FusedLocationProviderClient" is not import so how i can import this library and i also add all dependencies in build.gradle as well but i can't find any solution.
@barry007h
@barry007h 5 жыл бұрын
Same here, Documentation doesnt help either
@ვაკოვარდიშვილი
@ვაკოვარდიშვილი 5 жыл бұрын
add dependency in build.gradle folder implementation 'com.google.android.gms:play-services-location:15.0.1'
@k3nyon
@k3nyon 7 жыл бұрын
Hey man, where is the new videos? Don't stop please, you help me so much. Thank you.
@MaciejRzemek
@MaciejRzemek 6 жыл бұрын
I've seen that some of you got location on Googleplex! Any ideas how to fix that? ;)
@niclasb4860
@niclasb4860 7 жыл бұрын
I had an issue with the app crashing as soon as I opened the map. I solve the issue by updating build.gradle to a higher version (v.26).
@karaangmandirigma6095
@karaangmandirigma6095 6 жыл бұрын
howw ?
@abdelrahmanazab9515
@abdelrahmanazab9515 4 жыл бұрын
???
@truthseeker11
@truthseeker11 7 жыл бұрын
Ok, so here is a little bit of a work around if you're getting the Null Pointer Exception for your location. Just have the user turn on their location when the app opens. So, in the MainActivity, within the if(isServicesOK()) statement, place the statusCheck() method after the init() function. And here are the two methods. They will show a dialog if location is off. Once turned on, the app should work. :) Source code below. Credits from this Stack Overflow question - stackoverflow.com/questions/25175522/how-to-enable-location-access-programmatically-in-android: public void statusCheck() { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps(); } } private void buildAlertMessageNoGps() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Your GPS seems to be disabled, do you want to enable it?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { dialog.cancel(); } }); final AlertDialog alert = builder.create(); alert.show(); } Your onCreate method in the MainActivity class will look like this now: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(isServicesOK()) { init(); statusCheck(); //
@codingwithmitch
@codingwithmitch 7 жыл бұрын
Christopher Sheridan thanks
@pruthvikumar2258
@pruthvikumar2258 6 жыл бұрын
Am getting following error after adding getDeviceLocationMethod(Pls help me as am new to android) : E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering Tried stack overflow,nothing worked.Running on android kitkat version
@maaryjoseph730
@maaryjoseph730 6 жыл бұрын
lame but very important.. thanks christopher
@alricliew714
@alricliew714 6 жыл бұрын
Thanks. Christopher Sheridan
@soydevpro1323
@soydevpro1323 5 жыл бұрын
Thanks guys!!!
@kirpalsinghsh206
@kirpalsinghsh206 7 жыл бұрын
@MitchTabian The app crashes on my Samsung Note 3 when my GPS is turned off. Is there a way to display a message to turn on GPS to run the map or at least check if GPS is turned on
@jorgeoviedo732
@jorgeoviedo732 5 жыл бұрын
Hi Mitch, Thanks for the tutorial. Is what I was needing. Now I will need to know if is possible, how replace the blue dot in the User location for an Image or Icon. Thanks
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Using a marker cluster. Watch my google maps 2018 course. I show you that
@jorgeoviedo732
@jorgeoviedo732 5 жыл бұрын
@@codingwithmitch This is my actual code after the video. ... import android.Manifest; import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.Toast; import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.android.gms.maps.model.BitmapDescriptor; import com.google.android.gms.maps.model.BitmapDescriptorFactory; public class MiamiActivity extends AppCompatActivity implements OnMapReadyCallback { @Override public void onMapReady ( GoogleMap googleMap ) { Toast.makeText( this, "Map is Ready", Toast.LENGTH_SHORT ).show(); Log.d( TAG, "onMapReady: map is ready" ); mMap = googleMap; // Subway (2962 SW 8th) LatLng subway2962 = new LatLng(25.764590, -80.242120); mMap.setMapType( GoogleMap.MAP_TYPE_NORMAL ); mMap.addMarker(new MarkerOptions().position(subway2962).title("Subway")); // Moe’s Southwest Grill (Jackson Memorial) LatLng Moes_Southwest_Grill = new LatLng( 25.792320, -80.210830 ); mMap.addMarker( new MarkerOptions().position( Moes_Southwest_Grill ).title( "Moe’s Southwest Grill" ).icon( BitmapDescriptorFactory.defaultMarker( BitmapDescriptorFactory.HUE_VIOLET ) ) ); mMap.moveCamera( CameraUpdateFactory.newLatLng( Moes_Southwest_Grill ) ); // The Smoothie Shop (Brickell) LatLng The_Smoothie_Shop = new LatLng( 25.762160, -80.189110 ); mMap.addMarker( new MarkerOptions().position( The_Smoothie_Shop ).title( "The Smoothie Shop" ).icon( BitmapDescriptorFactory.defaultMarker( BitmapDescriptorFactory.HUE_VIOLET ) ) ); mMap.moveCamera( CameraUpdateFactory.newLatLng( The_Smoothie_Shop ) ); if (mLocationPermissionsGranted) { getDeviceLocation(); 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.setMyLocationEnabled( true ); } } private static final String TAG = "MapActivity"; private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION; private static final String COURSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION; private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234; private static final float DEFAULT_ZOOM = 15f; //vars private Boolean mLocationPermissionsGranted = false; private GoogleMap mMap; private FusedLocationProviderClient mFusedLocationProviderClient; @Override protected void onCreate ( @Nullable Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); setContentView( R.layout.activity_miami ); getLocationPermission(); } private void getDeviceLocation () { Log.d( TAG, "getDeviceLocation: getting the devices current location" ); mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient( this ); try { if (mLocationPermissionsGranted) { final Task location = mFusedLocationProviderClient.getLastLocation(); location.addOnCompleteListener( new OnCompleteListener() { @Override public void onComplete ( @NonNull Task task ) { if (task.isSuccessful()) { Log.d( TAG, "onComplete: found location!" ); Location currentLocation = (Location) task.getResult(); moveCamera( new LatLng( currentLocation.getLatitude(), currentLocation.getLongitude() ), DEFAULT_ZOOM ); } else { Log.d( TAG, "onComplete: current location is null" ); Toast.makeText( MiamiActivity.this, "unable to get current location", Toast.LENGTH_SHORT ).show(); } } } ); } } catch (SecurityException e) { Log.e( TAG, "getDeviceLocation: SecurityException: " + e.getMessage() ); } } private void moveCamera ( LatLng latLng, float zoom ) { Log.d( TAG, "moveCamera: moving the camera to: lat: " + latLng.latitude + ", lng: " + latLng.longitude ); CameraPosition cameraPosition = new CameraPosition.Builder() .target(latLng) // Sets the center of the map to User Location View .zoom(15) // Sets the zoom .bearing(90) // Sets the orientation of the camera to east .tilt(30) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); mMap.getUiSettings().setMyLocationButtonEnabled(true ); } private void initMap () { Log.d( TAG, "initMap: initializing map" ); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById( R.id.map ); mapFragment.getMapAsync( MiamiActivity.this ); } private void getLocationPermission () { Log.d( TAG, "getLocationPermission: getting location permissions" ); String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}; if (ContextCompat.checkSelfPermission( this.getApplicationContext(), FINE_LOCATION ) == PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission( this.getApplicationContext(), COURSE_LOCATION ) == PackageManager.PERMISSION_GRANTED) { mLocationPermissionsGranted = true; initMap(); } else { ActivityCompat.requestPermissions( this, permissions, LOCATION_PERMISSION_REQUEST_CODE ); } } else { ActivityCompat.requestPermissions( this, permissions, LOCATION_PERMISSION_REQUEST_CODE ); } } @Override public void onRequestPermissionsResult ( int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults ) { Log.d( TAG, "onRequestPermissionsResult: called." ); mLocationPermissionsGranted = false; switch (requestCode) { case LOCATION_PERMISSION_REQUEST_CODE: { if (grantResults.length > 0) { for (int i = 0; i < grantResults.length; i++) { if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { mLocationPermissionsGranted = false; Log.d( TAG, "onRequestPermissionsResult: permission failed" ); return; } } Log.d( TAG, "onRequestPermissionsResult: permission granted" ); mLocationPermissionsGranted = true; //initialize our map initMap(); } } } } } I Just adapted your explanation to my necessities. Now What I want is replace the blue dot that is added by default in user location for an Icon like a "Car". Idea is when the user open the app, show the Car(Icon) and not the blue dot, where the user is located(actual location). Thanks.
@shaniashi9906
@shaniashi9906 6 жыл бұрын
Hi Mitch, I use your code in my implementation, however, it seems that my current location is always at Googleplex, which is definitely incorrect. Do you have any idea why? Many Thanks!
@cforge2411
@cforge2411 6 жыл бұрын
did you start with GoogleMaps Activity or Empty Activity? in either case, let me know
@shaniashi9906
@shaniashi9906 6 жыл бұрын
Empty Activity with MapFragment. Thx
@cforge2411
@cforge2411 6 жыл бұрын
that seems weird. If the issue still exists, let me have a look at you code.
@Darkvan1661
@Darkvan1661 6 жыл бұрын
mine too - anyway to solve this problem?
@Darkvan1661
@Darkvan1661 6 жыл бұрын
@@cforge2411 I get the same error too - anyway to solve thisss. HELP
@keshavtangri571
@keshavtangri571 5 жыл бұрын
Hi Mitch, just like we added Latitude and Longitude in the Move camera function, can we add custom latitude longitude points and just dont move our camera there ?? Suppose I have some custom Lat and Long positions and what i want is that my current location is shown on the map , just like we did in this video and on the same map I should also see my custom latitude and Longitude markers... Can you help me with that ??? Anyone else who know how to do that can also comment and guide me through this. Any help is Welcome, Thanks in Advance !
@asarephilip
@asarephilip 7 жыл бұрын
Thanks so much... I was having difficulties implementing the FusedLocationProviderClient but i just find my way out after watching this tutorial. Big Ups :)
@ADC3131
@ADC3131 4 жыл бұрын
when I try implementing it, it says cannot resolve symbol can you help with this?
@faxmodem2397
@faxmodem2397 4 жыл бұрын
How many goals do I have in common with specific locations so that I can see my location online with goals? Is this possible? Can you help?
@funaustralia6517
@funaustralia6517 4 жыл бұрын
hi Mitch; if I using map in fragment, how can used initMap()? this is my coed private void initMap(){ Log.d(TAG,"initMap: initializing map"); SupportMapFragment mapFragment = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(NewMapFragment.this); } and public class NewMapFragment extends Fragment implements OnMapReadyCallback { but, when I using this coed private void getLocationPermission(){ Log.d(TAG,"getLocationPermission: getting location permissions"); String[] permission = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}; if(ContextCompat.checkSelfPermission(getActivity().getApplicationContext(),FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){ if(ContextCompat.checkSelfPermission(getActivity().getApplicationContext(),COURSE_LOCATION) == PackageManager.PERMISSION_GRANTED){ mLocationPermissionsGranted = true; initMap(); } else { ActivityCompat.requestPermissions(getActivity(),permission, LOCATION_PERMISSION_REQUEST_CODE); } }else { ActivityCompat.requestPermissions(getActivity(),permission, LOCATION_PERMISSION_REQUEST_CODE); } } and when I go to the newMapFragment, I will get NPE error java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.SupportMapFragment.getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)' on a null object reference at com.stanley.ifunpot.ui.NewMapFragment.initMap(NewMapFragment.java:113) so I need to call initMap() in getLocationPermission? or not? Because I cannot get my device location
@funaustralia6517
@funaustralia6517 4 жыл бұрын
Solve it. in oncreateview using this code SupportMapFragment mapFragment = (SupportMapFragment) this.getChildFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this);
@shivamsompura2234
@shivamsompura2234 6 жыл бұрын
location returned null !!!
@abirabed6193
@abirabed6193 4 жыл бұрын
i had the same problem change you google map api key
@l50406
@l50406 4 жыл бұрын
Make sure that the device location is on that was my problem.
@pruthvikumar2258
@pruthvikumar2258 6 жыл бұрын
Am getting following error after adding getDeviceLocationMethod(Pls help me as am new to android) : E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering Tried stack overflow,nothing worked.Running on android kitkat version
@shaon6996
@shaon6996 6 жыл бұрын
Your procedure does not work in Android API level 24 :( I can't get current device location in API 24 but it works all devices below API 24. 😒😖
@saqfinaqi2424
@saqfinaqi2424 6 жыл бұрын
you need to ask runtime permission to access user location
@Darkvan1661
@Darkvan1661 6 жыл бұрын
I can't seem to get device location - anyways to resolve this. the codes are the same as the provided source ode, so i don't seem to get the problem. HELP PLSS
@tsurugikyousuke3807
@tsurugikyousuke3807 6 жыл бұрын
Map pointer is showing but i need to scroll to see my pointer. Map is showing somewhere else. Help?
@MCFatDad1973
@MCFatDad1973 6 жыл бұрын
Could you add a video to save the state for when the devices orientation has changed. thanks. Your videos are great.
@abdulwahid_mohammed
@abdulwahid_mohammed 7 жыл бұрын
Thanks a lot we are waiting to the next .
@mixknowledge6420
@mixknowledge6420 6 жыл бұрын
FusedLocationproviderClient is not available in android studio??
@mixknowledge6420
@mixknowledge6420 6 жыл бұрын
leave it. thanks
@muhammadziaullah4621
@muhammadziaullah4621 6 жыл бұрын
@@mixknowledge6420 same problem
@muhammadziaullah4621
@muhammadziaullah4621 6 жыл бұрын
@@mixknowledge6420 any suggestion??
@alphazero0
@alphazero0 6 жыл бұрын
@@muhammadziaullah4621 add this in your depedencies implementation "com.google.android.gms:play-services-location:15.0.1"
@hgmusicse9885
@hgmusicse9885 6 жыл бұрын
Hi Mitch! I like your tutorials! I got a problem, after my latest update patch of Android Studio, my app crasches and I get this error msg; C:\Users\Admin\AndroidStudioProjects\Where_Am_I\app\src\main\java\com\example\admin\where_am_i\MapsActivity.java uses unchecked or unsafe operations. This line; location.addOnCompleteListener(new OnCompleteListener() is unchecked in the according to android studio. How do I solve this? I have searched the net, but find nothing to help me. Pls Help!
@chessamaulana3767
@chessamaulana3767 6 жыл бұрын
how to autotext method Log.d like you did in the video?
@Peesashit284
@Peesashit284 5 жыл бұрын
Hey Mitch, I my project was able to compile perfectly up untill this point, but I noticed that maps was incorrectly showing my location in GooglePlex, California. Any suggestions? I guessed there was something wrong with my getLocation method. I've checked and everything looks alright. Great course btw, very helpful!
@ВадимА-й8ф
@ВадимА-й8ф 5 жыл бұрын
do not forget to add this line to your code: .... if (currentLocation != null) { moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()), DEFAULT_ZOOM, "My Location"); }; .... if you don't, you will have NPУ when GPS is off
@ВадимА-й8ф
@ВадимА-й8ф 5 жыл бұрын
NPE*
@himanshunegi3216
@himanshunegi3216 5 жыл бұрын
I am getting null object reference on getMapAsync(), how should I solve this problem Please Help. I am a newbie. Thank You
@olukayodepaul7070
@olukayodepaul7070 5 жыл бұрын
is it possible to update sqlite room with update location instead of firebase
@jurasv2
@jurasv2 5 жыл бұрын
Hi, how can I check after all is localization is turn on, on the device?
@harithhusni8788
@harithhusni8788 6 жыл бұрын
hye mitch, where is the center button that can get our location ? i can't find the center button but my current location is detected. Hope u can help me.
@guilhermecalvi6568
@guilhermecalvi6568 5 жыл бұрын
Your tutorial is perfect, i love it.
@swathysoundar5276
@swathysoundar5276 6 жыл бұрын
hey I followed through your video but I'm not getting the device location help me out thanks
@halaalothman3574
@halaalothman3574 6 жыл бұрын
me too
@lotemmimon8385
@lotemmimon8385 6 жыл бұрын
me too
@rossglover7390
@rossglover7390 6 жыл бұрын
Any luck with this?
@rossglover7390
@rossglover7390 6 жыл бұрын
I have no errors but the location is simply not shown?
@ahmdshetya1604
@ahmdshetya1604 6 жыл бұрын
may be deprecated :[
@tamiroffen1079
@tamiroffen1079 6 жыл бұрын
I'm not getting the permissions pop-ups. Is this a problem? btw i'm still able to load the map.
@unicorngirlclemenz31
@unicorngirlclemenz31 6 жыл бұрын
Hey mich I get this error "Attempt to invoke virtual method 'double android.location.Location.getLatitude()' on a null object reference"
@kutubekkylychbekov2634
@kutubekkylychbekov2634 6 жыл бұрын
why if my location disabled on my device app doesn't request to enable it? how can i make it?
@rabiunislam9302
@rabiunislam9302 6 жыл бұрын
nice explanation and the flow of code
@fabricedesign9835
@fabricedesign9835 6 жыл бұрын
Hi, I'm french and when I run the app, my location appear near San José and not in france. Do you know why?
@cforge2411
@cforge2411 6 жыл бұрын
can you show your onMapReady method? i've a feeling there's the problem
@aleksanije5974
@aleksanije5974 4 жыл бұрын
@@cforge2411 I am getting exact same thig, map is showing that im in San Jose.
@robelhaftom4998
@robelhaftom4998 2 жыл бұрын
hey Mitch, first of all thank you for providing us this type of tutorial. I was developing the same GPS app and I used your tutor as a guide but in this part my device toasts ' unable to get current location ' message and I don't know how to fix it. please show me how to fix it
@maqumo1836
@maqumo1836 4 жыл бұрын
Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.moveCamera(com.google.android.gms.maps.CameraUpdate)' on a null object reference at com.example.geo_snap.MapsActivity.movecamera(MapsActivity.java:212) this error is coming only first time when i open.. please help me
@hiteshgarg6303
@hiteshgarg6303 7 жыл бұрын
Can you tell me how to do realtime tracking of another person having our app?
@kundandalmia2591
@kundandalmia2591 3 жыл бұрын
It returns GooglePlex for me when I getlastLocation() on emulator. Please help
@ShauryVerma
@ShauryVerma 6 жыл бұрын
This code without error run on Emulator and get random location but same code I will debug my cell phone then fire error on calling to moveCamera function why?
@user-rd1dm2dt9x
@user-rd1dm2dt9x 6 жыл бұрын
when I get latitude and longitude using location variable I'm getting error.
@arminlaghaee3910
@arminlaghaee3910 6 жыл бұрын
Tnx, for the video. When I want to find my current location, incited of showing me Burnaby,BC (where I live), it shows me Googlplex in USA. Idont know why? Is it because I am using the emulator not a phone.
@codingwithmitch
@codingwithmitch 6 жыл бұрын
Yes that would be my guess. I live in Langley, BC. Are you a student at UBC?
@cristiantamas9296
@cristiantamas9296 6 жыл бұрын
same here, on the phone is working, on the emulator showing mitch's location.
@kgpsoftminds2527
@kgpsoftminds2527 7 жыл бұрын
Thank you so much for the videos, they have been helping me so much. i started by buying your course. i want to ask how i could use this in a child fragment of a parent fragment found in a drawer. That's the problem am facing. if u could help me with some tips on how to work around. Thanks
@I_Nasir_Khattak
@I_Nasir_Khattak 6 жыл бұрын
ava.lang.NullPointerException: Attempt to invoke virtual method 'double android.location.Location.getLatitude()' on a null object reference ............. what is the error please explain
@zohaibshehzad5039
@zohaibshehzad5039 5 жыл бұрын
Hi Mitch! Does the location move when you move in any location ? Does it gives us real time location ? Waiting for your reply Thanks in Advance.
@siminam.michile4648
@siminam.michile4648 5 жыл бұрын
Idk if it helps but for me the real location finally worked when I added the 2nd else here (video 4, min 11:52) private void getLocationPermission(){ Log.d(TAG, "getLocationPermission: getting location permission"); String[] permission = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}; if(ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOC) == PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(this.getApplicationContext(), COARSE_LOC) == PackageManager.PERMISSION_GRANTED) { mLocatikonPermissionGranted = true; //1 initMap(); } else { ActivityCompat.requestPermissions(this, permission, LOCATION_PERM_REQUEST_CODE); } } // this one------------------------------------------------- else { ActivityCompat.requestPermissions(this, permission, LOCATION_PERM_REQUEST_CODE); } //---------------------------------------------- }
@zohaibshehzad5039
@zohaibshehzad5039 5 жыл бұрын
@@siminam.michile4648 Thanks 😊
@shababkm1803
@shababkm1803 7 жыл бұрын
You are a brilliant person, These tutorials are very useful for anyone who does not know about Android. I don't know anything about android. You taught me everything Thank you... You have to do me a favor. The Instagram application you have created makes it clear that all users will have to upload all user-uploaded photos instead of the following system. Can you please help me out? Can you please tell me the code of this method?
@chrisadikaram
@chrisadikaram 6 жыл бұрын
The mMap.setMyLocationEnabled(true); function does not seem to be setting the blue dot on the map
@shelle.y
@shelle.y 5 жыл бұрын
Comment out the line beneath it, I had the same problem and that's what worked for me!
@aneeshpv2626
@aneeshpv2626 7 жыл бұрын
Thanks a lot for this tutorial. Can you please explain how to receive location updates?
@Frankestine-id2wt
@Frankestine-id2wt 6 жыл бұрын
onMapReady is not called and setLocationEnabled also
@pegahes1079
@pegahes1079 6 жыл бұрын
if you get null location just add this line to your manifest
@udithasampath4991
@udithasampath4991 6 жыл бұрын
how can get selected place timezone ??? please suggest any calculation or method...
@nikkobanquil218
@nikkobanquil218 6 жыл бұрын
Hi sir, im getting "uses unchecked or unsafe operations. Recompile with -Xlint:unchecked for details." error. I dont even have a raw type arraylist here. Can you help me about this?
@chanukadesilva8920
@chanukadesilva8920 6 жыл бұрын
Create the Task as Task locationResult = mFusedLocationProviderClient.getLastLocation(); Then recreate the onCompleteListener
@anashamdi8992
@anashamdi8992 6 жыл бұрын
i have a problem icon not show when write mMap.getUiSetting().setMylocationButtonEnable(true)
@chrisadikaram
@chrisadikaram 6 жыл бұрын
I'm having a similar issue
@rahul8820
@rahul8820 5 жыл бұрын
sir getLatitude() is pointing to null reference exception. whats the way out for this
@rivodwiyulianto5642
@rivodwiyulianto5642 4 жыл бұрын
im also get this error do u already solve it? pls tell me
@ibrahemgamal3118
@ibrahemgamal3118 4 жыл бұрын
@@rivodwiyulianto5642 @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { if (task.getResult()!=null) { Location location = (Location) task.getResult(); MoveCamera(new LatLng(location.getLatitude(), location.getLongitude()), 15f); }else { LocationRequest locationRequest=LocationRequest.create(); locationRequest.setInterval(1000); locationRequest.setFastestInterval(5000); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); LocationCallback locationCallback=new LocationCallback(){ @Override public void onLocationResult(LocationResult locationResult) { if (locationResult==null){ return; }else { super.onLocationResult(locationResult); Location mlocation = locationResult.getLastLocation(); MoveCamera(new LatLng(mlocation.getLatitude(), mlocation.getLongitude()), 15f); } } }; fusedLocationProviderClient.requestLocationUpdates(locationRequest,locationCallback,null); look at this after getting task result check if it is null
@user_ahfvppkjb
@user_ahfvppkjb 4 жыл бұрын
I did everything same like you but location is always returned null, i checked the app's permission settings and it had the permission to access location enabled so what could be the problem. I appreciate your help.
@abdelrahmanazab9515
@abdelrahmanazab9515 4 жыл бұрын
You solve it?
@reiscollections01
@reiscollections01 6 жыл бұрын
Very Nice! Well explained! It helps me a lot. May i request if you could create a tutorial too on "Street View" . It would be great if you will make one :D !
@codingwithmitch
@codingwithmitch 6 жыл бұрын
I'll add it to the list lol
@scoutility
@scoutility 6 жыл бұрын
IF YOU ARE HAVING TROUBLE WITH FUSEDLOCATIONSERVICEPROVIDER: add the following to your build.gradle: implementation 'com.google.android.gms:play-services-location:15.0.1' make sure the version is the same as the other google play services SDKs you have implemented in gradle ie. all must be 15.0.1 in my case. Sync and you're done :) hope that helps anyone bc I had the same problem.
@irfaanpermana8524
@irfaanpermana8524 6 жыл бұрын
thanks bro :)
@rozikhan2604
@rozikhan2604 7 жыл бұрын
Love your courses. Can u start a course on Beacons?
@abimekonnen8231
@abimekonnen8231 4 жыл бұрын
u doing great God bless u
@bagaskaracahya7261
@bagaskaracahya7261 6 жыл бұрын
Hi! thanks for the tutorial u made, i just tried your code and i just found out there is an error in my code, its said that "error: cannot find symbol method getLatitude()" and "error: cannot find symbol method getLongitude()". how should i do to make this work ? hope you answer it, thanks!
@bagaskaracahya7261
@bagaskaracahya7261 6 жыл бұрын
nevermind, found it!
@abdullahishtiaq6537
@abdullahishtiaq6537 4 жыл бұрын
@@bagaskaracahya7261 plz i need solution of this error ...am still getting null location
@varshasrinivasan1340
@varshasrinivasan1340 7 жыл бұрын
The app shows me only the map. It doesn't automatically show me the location neither is the marker shown. Please help
@dipesh7512
@dipesh7512 7 жыл бұрын
Instead of Manually writing mapReady function create a new activity and select google Map activity ..Andriod studio will automatically create the code shown in part 3 of this series..which shows the marker as well
@cforge2411
@cforge2411 6 жыл бұрын
can you show your logcat?
@officialtopchefbeats
@officialtopchefbeats 6 жыл бұрын
how to you get the FusedLocationProviderClient? Mine is RED. Everything else is fine but for some reason, the FLPC won't work or react correctly. Help please. Thanks
@cristiantamas9296
@cristiantamas9296 6 жыл бұрын
you need this in your gradle: implementation 'com.google.android.gms:play-services-location:11.8.0'
@officialtopchefbeats
@officialtopchefbeats 6 жыл бұрын
Ah yeah, its been living in my gradle since the beginning of the project. It may be my laptop operating system, I just may need an upgrade
@saracastillo4495
@saracastillo4495 6 жыл бұрын
Hi! thanks for your video. It's great! but I have an issue.. I followed through your video and at beginning it worked, but now I'm not getting the device location (the blue dot dissapeared and the GPS icon isn't getting me back to my position) Coul anybody PLEASE help me out !?? thanks
@bilalyousaf6902
@bilalyousaf6902 5 жыл бұрын
hello sir I followed through your videos ...but I'm not getting the device location help me out please sir, thanks
@jayceewu8479
@jayceewu8479 5 жыл бұрын
SAme! i keep getting a null error
@markdelrosario4231
@markdelrosario4231 6 жыл бұрын
Hello can someone know how to set m my default location here in philippines?
@wissemrezki6072
@wissemrezki6072 4 жыл бұрын
How to change location on the maps longitude and latitude ?
@krishnagandhi4296
@krishnagandhi4296 6 жыл бұрын
How to make maps like uber? Can you help me out with it. Real Time Location
@bilalyousaf6902
@bilalyousaf6902 5 жыл бұрын
Hii sir..sir i m facing a problem... I am doing my final year project of BSIT ... My map is working but it doesn't show my device location and location symbol..please help me sir...i will be very grateful to you.
@abishekb18
@abishekb18 5 жыл бұрын
Just turn on location in your device
@madhurahlawat3093
@madhurahlawat3093 6 жыл бұрын
Cant resolve LocationService class Mitch. Help ASAP
@I3LACK-I3LOOD
@I3LACK-I3LOOD 6 жыл бұрын
Same Problem, did you solve?
@cforge2411
@cforge2411 6 жыл бұрын
I solved
@verdybangkityn1834
@verdybangkityn1834 6 жыл бұрын
how?
@songsab2
@songsab2 6 жыл бұрын
How to solve?
@subhamgoyal5289
@subhamgoyal5289 7 жыл бұрын
Sir ,can u make some video on family/friends tracking system
@josephjoey3904
@josephjoey3904 7 жыл бұрын
Hey whatsapp, 😁 that would be nice
@subhamgoyal5289
@subhamgoyal5289 7 жыл бұрын
Mitch Tabian yes sir.
@naniprasanna74
@naniprasanna74 7 жыл бұрын
please show me how to add google and Facebook login to Instagram clone App.. share a video on integration process. thankx
@naniprasanna74
@naniprasanna74 7 жыл бұрын
Actually I tried to integrate that stuff to this app, but its not working to me, I want to create an app by taking the reference of your app !!! that sounds good
@cforge2411
@cforge2411 6 жыл бұрын
you still need it?
@wongzq
@wongzq 6 жыл бұрын
For all those that have problems retrieving the device's current location (where it throws a NullPointerException) I added this line in the onCreate() function and it worked for me: mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); You can refer to the Google Developers Guide for this. developer.android.com/training/location/retrieve-current.html#java
@7mzsZyns
@7mzsZyns 6 жыл бұрын
didn't work :/
@weachris7412
@weachris7412 2 жыл бұрын
didnt work :(
@AmanGupta-ze7nt
@AmanGupta-ze7nt 6 жыл бұрын
there is error in *mFusedLocationProviderClient* and i tried other ways but its not working. and the main cause is:- E/UncaughtException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/api/Api$zzf; can anyone plz help.?
@svkrclg
@svkrclg 6 жыл бұрын
I am also getting the same problem
@AmanGupta-ze7nt
@AmanGupta-ze7nt 6 жыл бұрын
Saurav Kumar well i got some solution. In gradle.build dependencies you have to write the same version of implementation.. e.g. if firebase auth have 12.0.1 then other google services must have the same version.
@svkrclg
@svkrclg 6 жыл бұрын
Yes bro, It worked. Thanks for the help
@yoavshahrabani4574
@yoavshahrabani4574 6 жыл бұрын
loc.addOnCompleteListener return task, which task.getResult return null what can I do please help me. And how did you got phone emulator with gps?
@codingwithmitch
@codingwithmitch 6 жыл бұрын
It's not an emulator. That's a real device. I'm using a Google chrome extension called "vysor" to mirror the screen on the computer.
@yoavshahrabani4574
@yoavshahrabani4574 6 жыл бұрын
CodingWithMitch And how can you check it on a real device? Did you just connect it via usb? Or did you do more than that? Do you have a video on it? Thank you!
@cforge2411
@cforge2411 6 жыл бұрын
yes, with USB sometimes, there is some software needed too google has a age on it, try to find it if you can't , let me know
@samuelorji8396
@samuelorji8396 7 жыл бұрын
hey mitch,i am getting an error using the FusedLocationProviderClient object to get the location,its returning a null value for me ...and i have been on stackoverflow all day seeking a solution, i haven't found anything...any help will be much appreciated
@samuelorji8396
@samuelorji8396 7 жыл бұрын
Yes, i literally just copied your code from github into my project and its the same issue.. lemme attach a sample of the error message ****************************************************** Process: com.example.samuel.googlemaps, PID: 12847 java.lang.NullPointerException: Attempt to invoke virtual method 'double android.location.Location.getLatitude()' on a null object reference at com.example.samuel.googlemaps.MapActivity$1.onComplete(MapActivity.java:88) ********************************* I think another subscriber (Volkan Toprak) had the same issue
@samuelorji8396
@samuelorji8396 7 жыл бұрын
I tried using mock locations and they worked....the camera map was able to zoom over to the places..my guess is that the problem is from here final Task location = mFusedLocationProviderClient.getLastLocation(); cos the location is actually returning null
@samuelorji8396
@samuelorji8396 7 жыл бұрын
i have tried surrounding with a try/catch block, it caught the exception quite alright thus not making the camera to move to my location. I'll still keep on trying to debug it.Thanks so much for the response...really really means a lot
@samuelorji8396
@samuelorji8396 7 жыл бұрын
hey mitch, i think was able to find a workaround, according to this post *************** stackoverflow.com/a/29854418 *************************** i just opened google maps first...then ran the app and it ran smoothly...finally i can continue with the course......... i'll still try to see if that can be avoided though
@samuelorji8396
@samuelorji8396 7 жыл бұрын
Mitch Tabian just noticed that the GetLocation method only works when I have google maps actually running .....cos anytime I restart my phone and try ...it doesn't work... I saw something like fusedlocationclient.requireUpdates() ...as a method.....couldn't really understand it....maybe once I'm done with your course..I'll just create a new branch to use the method ....so I don't always have to use google maps ...Thanks.
@ubaidurrehman7668
@ubaidurrehman7668 6 жыл бұрын
my current location not shown .. please tell me the problem
@abdelrahmanazab9515
@abdelrahmanazab9515 4 жыл бұрын
??
@kiranmarrapu
@kiranmarrapu 6 жыл бұрын
A very nice article.
@niimisshagarg8064
@niimisshagarg8064 6 жыл бұрын
hello sir.....sir i m facing a problem...my map is not being shown...it is displaying everything except for the map...please help sir...i will be very grateful...
@bilalyousaf6902
@bilalyousaf6902 5 жыл бұрын
hii.. my map is working but it can't show device location,how you can solved it?
@aghaaful
@aghaaful 5 жыл бұрын
great work Sir!
@himanshunegi3216
@himanshunegi3216 5 жыл бұрын
hey bro I am getting null object reference on getMapAsync() what should I do Please Help. I am a newbie Thank You
@volkantoprak5132
@volkantoprak5132 7 жыл бұрын
Hello Mitch, first of all, thanks a lot for this awesome tutorial. I found an error. If user's last location is not known then null pointer exception occurs since currentLocation is null. This occurs if user did not turn on gps. I am still searching the best solution. I just wanted to inform you.
@samuelorji8396
@samuelorji8396 7 жыл бұрын
having the same error
@samuelorji8396
@samuelorji8396 7 жыл бұрын
try to run your default google maps and get your location first..then try the app again..mine worked after that .... i got it from this post stackoverflow.com/a/29854418
@subotai45
@subotai45 7 жыл бұрын
You can try to run the project in a physical android device instead of the emulator, that worked for me.
@ouahabhadilzineb2955
@ouahabhadilzineb2955 4 жыл бұрын
thank you so much god bless u
@gaoyunlong9403
@gaoyunlong9403 6 жыл бұрын
Anyone faced this error?Im stuck now! E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.a42411.myapplication, PID: 2082 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/api/Api$zzf;
@amarcool7530
@amarcool7530 6 жыл бұрын
Sir can you please make a video in which you we can know the current longitude and latitude with country name please sir please
@Anime-Freak714
@Anime-Freak714 6 жыл бұрын
activity_map is red(error) now can you please tell me how to solve this problem
@Anime-Freak714
@Anime-Freak714 6 жыл бұрын
its fine i fixed that problem
@bilalyousaf6902
@bilalyousaf6902 5 жыл бұрын
who got the solution of this video? I'm not getting device location help me out please...
@anasraza9709
@anasraza9709 5 жыл бұрын
If you are getting null pointer exception like "java.lang.NullPointerException: Attempt to invoke virtual method 'double android.location.Location.getLatitude()' on a null object reference" Cope this getDeviceLocation() method: public void getDeviceLocation(){ Log.d(TAG, "getDeviceLocation: getting the device current location"); fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); try { if(mLocationPermissionGranted){ Task task = fusedLocationProviderClient.getLastLocation(); task.addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Location location) { if(location != null){ Log.d(TAG, "onComplete: found location!"); moveCamera(new LatLng(location.getLatitude(),location.getLongitude()), DEFAULT_ZOOM); }else{ Log.d(TAG, "onComplete: current location is null"); Toast.makeText(GoogleMapsActivity.this,"Unable to get current location", Toast.LENGTH_LONG).show(); } } }); } }catch (SecurityException e){ Log.d(TAG, "getDeviceLocation: SecurityException: " + e.getMessage()); } }
@RShienh
@RShienh 6 жыл бұрын
FusedLocationProviderClient is deprecated
@markdelrosario4231
@markdelrosario4231 6 жыл бұрын
how do you fix that problem sir?
@RShienh
@RShienh 6 жыл бұрын
@@markdelrosario4231 I checked the documentation and found a way around. I don't remember it now.
@markdelrosario4231
@markdelrosario4231 6 жыл бұрын
i get it sir thank you! 😊
@nvlogs8916
@nvlogs8916 6 жыл бұрын
Great tutorials! Please make tutorials on Google directions Api Please Please Please!!!!! They will be very useful..........
@chimdikennacheta6843
@chimdikennacheta6843 7 жыл бұрын
Thanks Mitch!!!
Search a Location and Geolocate - [Android Google Maps Course]
12:46
CodingWithMitch
Рет қаралды 130 М.
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
I Redesigned the ENTIRE YouTube UI from Scratch
19:10
Juxtopposed
Рет қаралды 756 М.
Google Map in Android Studio | Google Map API Tutorial
9:04
CodeLabX
Рет қаралды 36 М.
DO NOT do this in a Software Engineering Interview
7:59
CodingWithMitch
Рет қаралды 9 М.
Android Studio GPS location tracker tutorial 01
6:25
Programming w/ Professor Sluiter
Рет қаралды 56 М.
How to implement Google Maps in your Android App.
8:03
tutorialsEU
Рет қаралды 143 М.
Implementing Google Maps on Android
7:17
Codeible
Рет қаралды 43 М.
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН