Android Application Google Map GetLastLocation - android

I developed an application using android studio. I used Google Maps in my application. When opening Google maps first I want the last location of the user using the code block below.
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
Location lastlocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
But user last location return null. How can I fix that problem?

Related

GPS Location Data Not Correct Display on Google Map

i'm setting a new project in flutter with flutter_google_maps for tracking user location on map it's a basic project
But when i am moving devices or ride then my Location are point on map but not right place
Ex.
I am walk on street road then google map navigation show exact my
location But my project not show exact location
Code are normal just use Flutter Location Plugin
And Track Location Using this code
location.onLocationChanged().listen((LocationData currentLocation) {
print(currentLocation.latitude);
print(currentLocation.longitude);
});
And set to marker target value describe in google_maps_flutter
i google lot of things but no answer found who resolve my problem
Where I'm wrong ya any other methods use by other location tracking app
Thanks

change latlng in google map directions api

i working with google map directions api in android application.when i send two Location to google api it return route between both but LatLng is changing and no one send me.Is there a way to do this?
You have to implement LocationListener to locate user's device GeoCode.
That will take some effort. You could refer the demo I made here mClima
The listener for location change was implemented in MainActivity. Remember to declare permision in AndroidManifest

Making a map on android

im trying to make an app on android just a typical map that utilizes a smartphones GPS and i am planning on using Dijkstra’s shortest path algorithm.
What i plan to do is make a top view map of an island and gather latitude and longitude data for each intersection on the islands road from my gps, join the image (the map of the island i made) with the latitude and longitude data then implement Dijkstra’s shortest path algorithm.
any suggestions?
how will i go about this?
first
Activity file
GoogleMap googleMap;
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
Follow the Getting Started
This guide is a quick start to adding a map to an Android app. Android Studio is the recommended development environment for building an app with the Google Maps Android API.
Step 1. Download Android Studio
Step 2. Install the Google Play services SDK
Step 3. Create a Google Maps project
Step 4. Get a Google Maps API key
Step 5. Hello Map! Take a look at the code
Step 6. Connect an Android device
Step 7. Build and run your app
Enabling GPS:
#Override
protected void onStart() {
super.onStart(); // Always call the superclass method first
// The activity is either being restarted or started for the first time
// so this is where we should make sure that GPS is enabled
LocationManager locationManager =
(LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!gpsEnabled) {
// Create a dialog here that requests the user to enable GPS, and use an intent
// with the android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS action
// to take the user to the Settings screen to enable GPS when they click "OK"
}
}
Hope this helps!

Android Google Maps Api v2 . How get altitude anywhere?

I want get altitude anywhere my from android phone.
I searching a methods like this way:
{Altitude newAltitude=new Altitude( double latitude,double longitude);}
As a result i will set latitude and longitude then i must get altitude from this (specific) location. I want just Altitude value.
Is there any methods like this.I will use Google Maps Api v2.
Google Play Services location libraries give access to the altitude.
Please see:
http://developer.android.com/google/play-services/setup.html
http://developer.android.com/training/location/retrieve-current.html

Searching option in google map in android

i have successfully displayed google map in my app . but i am not able to search the specfied location . can u please put the code snippet or any link available for the code .
To get a location (latitude and longitude) from a location name(e.g. "paris" or "japan"), use Geocoder.getFromLocationName()
To display a specific latitude/longitude on the map use MapControl.setCenter()

Categories

Resources