2
2
3
3
import java .io .IOException ;
4
4
import java .util .AbstractList ;
5
+ import java .util .ArrayList ;
5
6
import java .util .List ;
6
7
import java .util .Locale ;
7
8
import java .util .Map ;
@@ -70,14 +71,14 @@ public Location getMyLocation()
70
71
{
71
72
LocationManager service = (LocationManager ) context .getSystemService (Context .LOCATION_SERVICE );
72
73
boolean enabledGPS = service .isProviderEnabled (LocationManager .GPS_PROVIDER );
73
-
74
+
74
75
//boolean enabledWiFi = service.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
75
76
76
77
// Check if enabled and if not send user to the GSP settings
77
78
// Better solution would be to display a dialog and suggesting to
78
79
// go to the settings
79
80
if (!enabledGPS ) {
80
- Toast .makeText (context , "GPS signal not found" , Toast .LENGTH_LONG ).show ();
81
+ Toast .makeText (context , "GPS signal not found" , Toast .LENGTH_SHORT ).show ();
81
82
//Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
82
83
//startActivity(intent);
83
84
}
@@ -101,35 +102,38 @@ public Location getMyLocation()
101
102
//do something
102
103
}
103
104
String test = "Dernière connue:" + getAddress (myLocation .getLatitude (),myLocation .getLongitude ());
104
- Toast .makeText (context , test , Toast .LENGTH_LONG ).show ();
105
+ Toast .makeText (context , test , Toast .LENGTH_SHORT ).show ();
105
106
106
107
107
108
return myLocation ;
108
109
109
110
}
110
111
111
- public TreeMap <Integer ,Float > getNearestStoresOnMap ( AbstractList <Store > allstores )
112
+ @ SuppressWarnings ("null" )
113
+ public AbstractList <Store > getNearestStoresOnMap ( AbstractList <Store > allstores )
112
114
{
113
- Map < Integer , Float > h = new TreeMap < Integer , Float >();
115
+
114
116
Location myLoc = getMyLocation ();
115
117
Location locationA = new Location ("" );
116
-
118
+ AbstractList < Store > storesList = new ArrayList < Store >();
117
119
118
120
if (allstores != null ) {
119
121
for (Store store : allstores ) {
120
122
121
- locationA .setLatitude (store .getLatitude ());
122
- locationA .setLongitude (store .getLongitude ());
123
+ if (store != null )
124
+ {
125
+ locationA .setLatitude (store .getLatitude ());
126
+ locationA .setLongitude (store .getLongitude ());
123
127
124
- float distance = myLoc .distanceTo (locationA ) / 1000 ;
125
-
126
- Toast .makeText (context ,String .valueOf (distance ), Toast .LENGTH_LONG ).show ();
127
- h .put (store .getId (), distance );
128
+ float distance = myLoc .distanceTo (locationA ) / 1000 ;
128
129
130
+ if (distance < 50.00 )
131
+ storesList .add (store );
132
+ }
129
133
}
130
134
}
131
135
132
- return ( TreeMap < Integer , Float >) h ;
136
+ return storesList ;
133
137
134
138
}
135
139
@@ -168,20 +172,11 @@ public void onLocationChanged(Location arg0) {
168
172
@ Override
169
173
public void onInfoWindowClick (Marker arg0 ) {
170
174
// TODO Auto-generated method stub
171
-
175
+
172
176
}
173
177
174
178
@ Override
175
179
public void onMapLongClick (LatLng arg0 ) {
176
180
// TODO Auto-generated method stub
177
-
178
181
}
179
-
180
- // Location sydney = new Location("23 rue du dépot 62000 Arras");
181
-
182
- //String test = getAddress(53.558, 9.927);
183
- //Toast.makeText(this, test, Toast.LENGTH_LONG).show();
184
-
185
- //float test = map.getMyLocation().distanceTo(sydney);
186
-
187
182
}
0 commit comments