0

Is this something which is updated to different method or am i doing something wrong?
I want to get my current location on Google Maps what am doing right now is as follows.

Creating GoogleMaps Activity,
Download GooglePlay Services from Android SDK Manager,
Giving Permissions in AndroidManifest for Internet and Location

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>

Giving permission to use my location in OnMapReady

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    mMap.setMapType(googleMap.MAP_TYPE_TERRAIN);

    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);
}

When i try to run this code at my device LG Spirit H440 I doesn't get what i expect to get, it should give me the option to get my current location with blue dot on the maps.

I have created also API KEY in the Google API's console.

What am i doing wrong?

Edited by Stefan_1

2
Contributors
1
Reply
11
Views
3 Months
Discussion Span
Last Post by Daniel_87
0

Hello Stefan,

I will sugesst to answer your question is Get Current Location GoogleMaps API Android

Please check the sample code for the Google Maps Android API v2. Using this will solve your problem.

private void setUpMapIfNeeded() {

            // Do a null check to confirm that we have not already instantiated the map.

        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            mMap.setMyLocationEnabled(true);
            // Check if we were successful in obtaining the map.
            if (mMap != null) {

             mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {

           @Override
           public void onMyLocationChange(Location arg0) {
            // TODO Auto-generated method stub

             mMap.addMarker(new MarkerOptions().position(new LatLng(arg0.getLatitude(), arg0.getLongitude())).title("It's Me!"));
           }
          });

            }
        }
    }

Call this function in onCreate function.

Regards,
Daniel (Tech.Suppoert)
TechTIQ Solutions,

Edited by Daniel_87

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.