Google Maps issue, default location button doesnt work and default icon isn´t showed

I didn´t make a backup of my app when it was working well. My issue is that the location button is not working now, and there isn´t showed an icon (default icon) for my actual position.... Help would be apreciated.

Thanks!

This is the Fragment class:

package google.Bi;




import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.List;

import org.json.JSONObject;

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.Fragment;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
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 android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.ViewGroup;
import android.widget.TextView;
import android.app.AlertDialog;
import android.app.Service;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.IBinder;
import android.provider.Settings;
import android.util.Log;
import android.app.Dialog;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;


public class mapfragmentplaces extends Fragment implements LocationListener {


protected LocationManager locationManager;
// GoogleMap googleMap;

LatLng myPosition;
private SupportMapFragment map;
private GoogleMap mMapView;


int fragVal2;
static Context ontext;
private static View view;


//lo que se ocupa para construir los sitios

String[] mPlaceType=null;
String[] mPlaceTypeName=null;

double mLatitude=0;
double mLongitude=0;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        if (view != null) {
            ViewGroup parent = (ViewGroup) view.getParent();
            if (parent != null) {
                parent.removeView(view);
               view = null;
            }
        } 

        try {
            view = inflater.inflate(R.layout.fragment_layout, container, false);
        android.support.v4.app.FragmentManager fm = getFragmentManager();

            /*
            GoogleMapOptions gmo = (new GoogleMapOptions()).zoomControlsEnabled(false).rotateGesturesEnabled(false);
            SupportMapFragment mapFragment = SupportMapFragment.newInstance(gmo);
            android.support.v4.app.FragmentTransaction fragmentTransaction = getFragmentManager()     .beginTransaction();
            fragmentTransaction.add(R.id.mapFragmentHole, mapFragment);
            fragmentTransaction.commit();

            GoogleMap map = mapFragment.getMap();   */

            map = (SupportMapFragment) fm.findFragmentById(R.id.map);


            if (map == null) {
                map = SupportMapFragment.newInstance();
                fm.beginTransaction().replace(R.id.map, map).commit();
            }


            //  mMapView = fm.getMap();
            mMapView = map.getMap();
                // Enabling MyLocation Layer of Google Map
            mMapView.setMyLocationEnabled(true);

            // Getting LocationManager object from System Service LOCATION_SERVICE
            LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

            // Creating a criteria object to retrieve provider
             Criteria criteria = new Criteria();

            // Getting the name of the best provider
            String provider = locationManager.getBestProvider(criteria, true);

            // Getting Current Location From GPS
             Location location = locationManager.getLastKnownLocation(provider);

            if(location!=null){
                onLocationChanged(location);
       }

           locationManager.requestLocationUpdates(provider, 20000, 0, this);





            // Clears all the existing markers 
            mMapView.clear();

            final String Lugar = "Plaza fiesta";
            String  Desc = "Lugar bonito";

                Double Lat3 = 25.751188242782035;
                Double Lng3 = -100.3097140789032;

//                      notificacion(Results.toString());
                mMapView.addMarker(new MarkerOptions()
                          .position(new LatLng(Lat3,Lng3))
                          .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker1))
                          .title(Lugar)
                          .snippet(Desc));

            /*  mMapView.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
                    @Override
                    public void onInfoWindowClick(Marker marker) {
                       Intent intent = new Intent(getActivity(), Stores.class);
                       startActivity(intent);

                    }
                }); */

                mMapView.setOnMarkerClickListener(new OnMarkerClickListener() {

                    @Override
                    public boolean onMarkerClick(Marker marker) {
                        // TODO Auto-generated method stub
                        Intent intent2 = null;
                         if(marker.getTitle().equals(Lugar)) // if marker source is clicked
                          { intent2 = new Intent(getActivity(), Stores2.class);
                           startActivity(intent2);
                          } else
                          {
                              marker.showInfoWindow();

                          }
                           return true;
                    } 


                 });  




                List<HashMap<String, String>> list = setPlaceTag.getList();
                String we[] = setPlaceTag.getFinals2();
                String we2[]    = setPlaceTag.getFinals3();
                LatLng we3[]    = setPlaceTag.getFinals4();
                if (list!=null){
            //((Menu) map).clear();
            for(int i=0;i<list.size();i++){


                // Creating a marker
                MarkerOptions markerOptions = new MarkerOptions();

                // Getting a place from the places list
                HashMap<String, String> hmPlace = list.get(i);

                // Getting latitude of the place
                double lat = Double.parseDouble(hmPlace.get("lat"));                

                // Getting longitude of the place
                double lng = Double.parseDouble(hmPlace.get("lng"));

                // Getting name
                String name = hmPlace.get("place_name");

                // Getting vicinity
                String vicinity = hmPlace.get("vicinity");

                LatLng latLng = new LatLng(lat, lng);

                // Setting the position for the marker
                markerOptions.position(latLng);

                // Setting the title for the marker. 
                //This will be displayed on taping the marker
                markerOptions.title(name + " : " + vicinity);

               if( we[setPlaceTag.getPosition()].equals(name) && we2[setPlaceTag.getPosition()].equals(vicinity) 
                       && we3[setPlaceTag.getPosition()].equals(latLng)){
                    markerOptions.position(latLng).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
                    } 
                // Placing a marker on the touched position
                mMapView.addMarker(markerOptions);            

            }
                }


        } catch (InflateException e) {
            /* map is already there, just return view as it is */
        }



        /*if(anterior!=actual){

            Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
            getFragmentManager().beginTransaction().remove(fragment).commit(); 

        } */


        return view;
        }


    @Override
    public void onLocationChanged(Location location) {
        mLatitude = location.getLatitude();
        mLongitude = location.getLongitude();
        LatLng latLng16 = new LatLng(mLatitude, mLongitude);

        /* Double Lat3 = 25.751188242782035;
        Double Lng3 = -100.3097140789032;
        LatLng latLng = new LatLng(Lat3, Lng3); */
        mMapView.moveCamera(CameraUpdateFactory.newLatLng(latLng16));
        mMapView.animateCamera(CameraUpdateFactory.zoomTo(12));

    }

    @Override
        public void onResume() {
            // TODO Auto-generated method stub


            super.onResume();
        }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

     @Override
        public void onDestroyView() {

            super.onDestroyView();
            map = SupportMapFragment.newInstance();
           /* android.support.v4.app.FragmentTransaction fragmentTransaction =
                     getChildFragmentManager().beginTransaction();
             fragmentTransaction.add(R.id.map, map);
             fragmentTransaction.commit();  */

            Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
            if (fragment != null){
                getFragmentManager().beginTransaction().remove(fragment).commit();}
        }

}

onLocation is taking me to center the map on my actual location , but I would like to have the default icon from google and also that the location button works... thanks.

Answers


IF YOUR LOCATION BUTTON DOESNT WORK AND THE ICON ISN´T SHOWED:

1 - make sure your app has all gps permissions.

2 - check your manifest for the permissions in 324464556 tutorials are on internet.

3 - Check things like @Mateusz Jablonski said about my code...

4 - If none of them work and you´re sure the structure of your app is correct... go to 5

5 - Restart you´re phone. Maybe some dev options you change... or some bug was made while working on it.


Need Your Help

How to Access Application Config from View in Zend Framework 2 (zf2)?

zend-framework2 zend-view

I wanted to access the application config from a view. How can I achieve that in ZF 2?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.