Skip to content
This repository was archived by the owner on Dec 10, 2022. It is now read-only.

Commit 93d10c1

Browse files
committed
finitions sur map
1 parent 94c4e1e commit 93d10c1

File tree

6 files changed

+31
-28
lines changed

6 files changed

+31
-28
lines changed

res/drawable-hdpi/ic_launcher.png

-1.17 KB
Loading

res/drawable-mdpi/ic_launcher.png

-329 Bytes
Loading

res/drawable-xhdpi/ic_launcher.png

-2.32 KB
Loading

res/drawable-xxhdpi/ic_launcher.png

-5 KB
Loading

src/com/epsi/VignPerzMal/activities/MainActivity.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ protected void onCreate(Bundle savedInstanceState) {
6161
btnList = (Button)findViewById(R.id.btnList);
6262

6363
MapFragment fragment = (MapFragment)getFragmentManager().findFragmentById(R.id.map);
64+
65+
View fragmentLayout = findViewById(R.id.map);
66+
fragmentLayout.setVisibility(View.INVISIBLE);
67+
6468
map = fragment.getMap();
6569
map.setMyLocationEnabled(true);
6670
map.getUiSettings().setMyLocationButtonEnabled(true);
@@ -151,20 +155,24 @@ else if(zipCode.length() == 0)
151155
displayStores();
152156
}
153157

158+
/* get nerarest stores from location */
154159
private void searchAroundMe() {
155160

156-
TreeMap<Integer,Float> listNear = myMap.getNearestStoresOnMap(dal.get());
157-
myMap.setStoresOnMap(map , stores);
161+
AbstractList<Store> abstores = myMap.getNearestStoresOnMap(dal.get());
162+
myMap.setStoresOnMap(map , abstores);
163+
stores = myMap.getNearestStoresOnMap(dal.get());
164+
displayStores();
158165
}
159166

167+
/* Display Map on bouton click */
160168
private void showMap() {
161169

162-
ListView listviewLayout = (ListView) findViewById(R.id.lvStores);
163-
listviewLayout.setVisibility(View.GONE);
164-
165170
View fragmentLayout = findViewById(R.id.map);
166171
fragmentLayout.setVisibility(View.VISIBLE);
167172

173+
ListView listviewLayout = (ListView) findViewById(R.id.lvStores);
174+
listviewLayout.setVisibility(View.GONE);
175+
168176
String zipCode = etZipCode.getText().toString();
169177

170178
AbstractList<Store> allstores;

src/com/epsi/VignPerzMal/model/gMap.java

+18-23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.util.AbstractList;
5+
import java.util.ArrayList;
56
import java.util.List;
67
import java.util.Locale;
78
import java.util.Map;
@@ -70,14 +71,14 @@ public Location getMyLocation()
7071
{
7172
LocationManager service = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
7273
boolean enabledGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
73-
74+
7475
//boolean enabledWiFi = service.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
7576

7677
// Check if enabled and if not send user to the GSP settings
7778
// Better solution would be to display a dialog and suggesting to
7879
// go to the settings
7980
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();
8182
//Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
8283
//startActivity(intent);
8384
}
@@ -101,35 +102,38 @@ public Location getMyLocation()
101102
//do something
102103
}
103104
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();
105106

106107

107108
return myLocation;
108109

109110
}
110111

111-
public TreeMap<Integer,Float> getNearestStoresOnMap( AbstractList<Store> allstores)
112+
@SuppressWarnings("null")
113+
public AbstractList<Store> getNearestStoresOnMap( AbstractList<Store> allstores)
112114
{
113-
Map<Integer,Float> h = new TreeMap<Integer,Float>();
115+
114116
Location myLoc = getMyLocation();
115117
Location locationA = new Location("");
116-
118+
AbstractList<Store> storesList = new ArrayList<Store>();
117119

118120
if(allstores != null) {
119121
for(Store store : allstores) {
120122

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());
123127

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;
128129

130+
if (distance < 50.00)
131+
storesList.add(store);
132+
}
129133
}
130134
}
131135

132-
return (TreeMap<Integer, Float>) h;
136+
return storesList;
133137

134138
}
135139

@@ -168,20 +172,11 @@ public void onLocationChanged(Location arg0) {
168172
@Override
169173
public void onInfoWindowClick(Marker arg0) {
170174
// TODO Auto-generated method stub
171-
175+
172176
}
173177

174178
@Override
175179
public void onMapLongClick(LatLng arg0) {
176180
// TODO Auto-generated method stub
177-
178181
}
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-
187182
}

0 commit comments

Comments
 (0)