package rs.elfak.mosis.marko.discounthunt;

import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

import org.json.JSONException;
import org.json.JSONObject;

public class CurrentLocation {
    private LocationListener mLocationListener;
    private LocationManager mLocationManager;
    private double lat, lng;

    public CurrentLocation(LocationManager locationManager){
        mLocationManager = locationManager;
        mLocationListener = new LocationListener() {
            @Override
            public void onLocationChanged(android.location.Location location) {
                lat = location.getLatitude();
                lng = location.getLongitude();
            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {

            }

            @Override
            public void onProviderEnabled(String provider) {

            }

            @Override
            public void onProviderDisabled(String provider) {

            }
        };
        try {
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, mLocationListener);
            mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0, mLocationListener);
        }catch (SecurityException ex) {
            System.out.println("Error!");
        }
    }

    public JSONObject toJSONObject() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("lat", lat);
            jsonObject.put("lng", lng);
        }catch (JSONException ex) {}
        return jsonObject;
    }
}

@@ -37,16 +37,50 @@
 thunt;%0A%0A
+import android.location.Location;%0A
 import a
@@ -181,16 +181,102 @@
 undle;%0A%0A
+import com.android.volley.Response;%0Aimport com.google.android.gms.maps.model.LatLng;%0A%0A
 import o
@@ -468,21 +468,69 @@
 ate 
-double lat, l
+Response.Listener%3CLocation%3E listener;%0A    private LatLng latL
 ng;%0A
@@ -591,16 +591,51 @@
 nager)%7B%0A
+        latLng = new LatLng(0, 0);%0A
         
@@ -844,19 +844,33 @@
      lat
- = 
+Lng = new LatLng(
 location
@@ -887,56 +887,142 @@
 de()
-;%0A                lng = location.getLongitude();
+, location.getLongitude());%0A                if(listener != null)%7B%0A                    listener.onResponse(location);%0A                %7D
 %0A   
@@ -1701,24 +1701,133 @@
    %7D%0A    %7D%0A%0A
+    public void setListener(Response.Listener%3CLocation%3E listener) %7B%0A        this.listener = listener;%0A    %7D%0A%0A
     public J
@@ -1954,16 +1954,28 @@
 at%22, lat
+Lng.latitude
 );%0A     
@@ -2004,18 +2004,31 @@
 %22lng%22, l
-ng
+atLng.longitude
 );%0A     
@@ -2091,11 +2091,73 @@
 t;%0A    %7D
+%0A%0A    public LatLng getLatLng() %7B%0A        return latLng;%0A    %7D
 %0A%7D%0A

Update CurrentLocation to store LatLng and support a listener