Issue
I want to display a MapView with the device location and every 10 seconds the location is updated. I've found a lot of solutions and no ones works, even the official Google Maps API doesn't works. My code right now is the basic MapActivity:
package org.cuatrovientos.app.pamplonanegra;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
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.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// 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);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Pamplona, Spain.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Cuatrovientos and move the camera
LatLng cuatrovientos = new LatLng(42.82452261, -1.6601049900);
mMap.addMarker(new MarkerOptions().position(cuatrovientos).title("Marker in Cuatrovientos"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(cuatrovientos));
}
}
I have this permissions:
<!-- Permisions -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.LOCATION" />
<uses-permission android:name="android.permission.PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
Of course I have the Google API Key right in the manifest and this compile in the build.gradle for the app:
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.android.gms:play-services-location:11.0.4'
How can I do that? Thanks
Solution
You aren't requesting the user location in your code, you are only showing a map and moving the camera.
You need to request it as described in the docs
Some relevant code:
mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
})
.addOnFailureListener(new OnFailureListener() {
(...)
}
});
EDIT: For using the last version of the libraries, you must add Google Repository to your paren't project build.gradle, in this way:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
It will be of help that you keep update your SDK dependencies, especially the "Google Repository"
Answered By - webo80
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.