@@ -39,34 +39,34 @@ public NearbyController(NearbyPlaces nearbyPlaces) {
39
39
/**
40
40
* Prepares Place list to make their distance information update later.
41
41
*
42
- * @param curLatLng current ___location for user
43
- * @param searchLatLng the ___location user wants to search around
42
+ * @param curLatLng current ___location for user
43
+ * @param searchLatLng the ___location user wants to search around
44
44
* @param returnClosestResult if this search is done to find closest result or all results
45
- * @param customQuery if this search is done via an advanced query
46
- * @return NearbyPlacesInfo a variable holds Place list without distance information
47
- * and boundary coordinates of current Place List
45
+ * @param customQuery if this search is done via an advanced query
46
+ * @return NearbyPlacesInfo a variable holds Place list without distance information and
47
+ * boundary coordinates of current Place List
48
48
*/
49
- public NearbyPlacesInfo loadAttractionsFromLocation (final LatLng curLatLng , final LatLng searchLatLng ,
49
+ public NearbyPlacesInfo loadAttractionsFromLocation (final LatLng curLatLng ,
50
+ final LatLng searchLatLng ,
50
51
final boolean returnClosestResult , final boolean checkingAroundCurrentLocation ,
51
- final boolean shouldQueryForMonuments , @ Nullable final String customQuery ) throws Exception {
52
+ @ Nullable final String customQuery ) throws Exception {
52
53
53
54
Timber .d ("Loading attractions near %s" , searchLatLng );
54
55
NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo ();
55
-
56
56
if (searchLatLng == null ) {
57
57
Timber .d ("Loading attractions nearby, but curLatLng is null" );
58
58
return null ;
59
59
}
60
60
List <Place > places = nearbyPlaces
61
61
.radiusExpander (searchLatLng , Locale .getDefault ().getLanguage (), returnClosestResult ,
62
- shouldQueryForMonuments , customQuery );
62
+ customQuery );
63
63
64
64
if (null != places && places .size () > 0 ) {
65
- LatLng [] boundaryCoordinates = {places . get ( 0 ). ___location , // south
66
- places .get (0 ).___location , // north
67
- places .get (0 ).___location , // west
68
- places .get (0 ).___location }; // east, init with a random ___location
69
-
65
+ LatLng [] boundaryCoordinates = {
66
+ places .get (0 ).___location , // south
67
+ places .get (0 ).___location , // north
68
+ places .get (0 ).___location , // west
69
+ places . get ( 0 ). ___location }; // east, init with a random ___location
70
70
71
71
if (curLatLng != null ) {
72
72
Timber .d ("Sorting places by distance..." );
@@ -88,11 +88,11 @@ public NearbyPlacesInfo loadAttractionsFromLocation(final LatLng curLatLng, fina
88
88
}
89
89
}
90
90
Collections .sort (places ,
91
- (lhs , rhs ) -> {
92
- double lhsDistance = distances .get (lhs );
93
- double rhsDistance = distances .get (rhs );
94
- return (int ) (lhsDistance - rhsDistance );
95
- }
91
+ (lhs , rhs ) -> {
92
+ double lhsDistance = distances .get (lhs );
93
+ double rhsDistance = distances .get (rhs );
94
+ return (int ) (lhsDistance - rhsDistance );
95
+ }
96
96
);
97
97
}
98
98
nearbyPlacesInfo .curLatLng = curLatLng ;
@@ -104,11 +104,11 @@ public NearbyPlacesInfo loadAttractionsFromLocation(final LatLng curLatLng, fina
104
104
if (!returnClosestResult ) {
105
105
// To remember latest search either around user or any point on map
106
106
latestSearchLocation = searchLatLng ;
107
- latestSearchRadius = nearbyPlaces .radius * 1000 ; // to meter
107
+ latestSearchRadius = nearbyPlaces .radius * 1000 ; // to meter
108
108
109
109
// Our radius searched around us, will be used to understand when user search their own ___location, we will follow them
110
110
if (checkingAroundCurrentLocation ) {
111
- currentLocationSearchRadius = nearbyPlaces .radius * 1000 ; // to meter
111
+ currentLocationSearchRadius = nearbyPlaces .radius * 1000 ; // to meter
112
112
currentLocation = curLatLng ;
113
113
}
114
114
}
@@ -118,6 +118,98 @@ public NearbyPlacesInfo loadAttractionsFromLocation(final LatLng curLatLng, fina
118
118
return nearbyPlacesInfo ;
119
119
}
120
120
121
+ /**
122
+ * Prepares Place list to make their distance information update later.
123
+ *
124
+ * @param curLatLng The current latitude and longitude.
125
+ * @param screenTopRight The top right corner of the screen (latitude,
126
+ * longitude).
127
+ * @param screenBottomLeft The bottom left corner of the screen (latitude,
128
+ * longitude).
129
+ * @param searchLatLng The latitude and longitude of the search ___location.
130
+ * @param returnClosestResult Flag indicating whether to return the closest result.
131
+ * @param checkingAroundCurrentLocation Flag indicating whether to check around the current
132
+ * ___location.
133
+ * @param shouldQueryForMonuments Flag indicating whether to include monuments in the
134
+ * query.
135
+ * @param customQuery Optional custom SPARQL query to use instead of default
136
+ * queries.
137
+ * @return An object containing information about nearby places.
138
+ * @throws Exception If an error occurs during the retrieval process.
139
+ */
140
+ public NearbyPlacesInfo loadAttractionsFromLocation (final LatLng curLatLng ,
141
+ final fr .free .nrw .commons .___location .LatLng screenTopRight ,
142
+ final fr .free .nrw .commons .___location .LatLng screenBottomLeft , final LatLng searchLatLng ,
143
+ final boolean returnClosestResult , final boolean checkingAroundCurrentLocation ,
144
+ final boolean shouldQueryForMonuments , @ Nullable final String customQuery )
145
+ throws Exception {
146
+
147
+ Timber .d ("Loading attractions near %s" , searchLatLng );
148
+ NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo ();
149
+
150
+ if (searchLatLng == null ) {
151
+ Timber .d ("Loading attractions nearby, but curLatLng is null" );
152
+ return null ;
153
+ }
154
+
155
+ List <Place > places = nearbyPlaces .getFromWikidataQuery (screenTopRight , screenBottomLeft ,
156
+ Locale .getDefault ().getLanguage (), shouldQueryForMonuments , customQuery );
157
+
158
+ if (null != places && places .size () > 0 ) {
159
+ LatLng [] boundaryCoordinates = {
160
+ places .get (0 ).___location , // south
161
+ places .get (0 ).___location , // north
162
+ places .get (0 ).___location , // west
163
+ places .get (0 ).___location };// east, init with a random ___location
164
+
165
+ if (curLatLng != null ) {
166
+ Timber .d ("Sorting places by distance..." );
167
+ final Map <Place , Double > distances = new HashMap <>();
168
+ for (Place place : places ) {
169
+ distances .put (place , computeDistanceBetween (place .___location , curLatLng ));
170
+ // Find boundaries with basic find max approach
171
+ if (place .___location .getLatitude () < boundaryCoordinates [0 ].getLatitude ()) {
172
+ boundaryCoordinates [0 ] = place .___location ;
173
+ }
174
+ if (place .___location .getLatitude () > boundaryCoordinates [1 ].getLatitude ()) {
175
+ boundaryCoordinates [1 ] = place .___location ;
176
+ }
177
+ if (place .___location .getLongitude () < boundaryCoordinates [2 ].getLongitude ()) {
178
+ boundaryCoordinates [2 ] = place .___location ;
179
+ }
180
+ if (place .___location .getLongitude () > boundaryCoordinates [3 ].getLongitude ()) {
181
+ boundaryCoordinates [3 ] = place .___location ;
182
+ }
183
+ }
184
+ Collections .sort (places ,
185
+ (lhs , rhs ) -> {
186
+ double lhsDistance = distances .get (lhs );
187
+ double rhsDistance = distances .get (rhs );
188
+ return (int ) (lhsDistance - rhsDistance );
189
+ }
190
+ );
191
+ }
192
+ nearbyPlacesInfo .curLatLng = curLatLng ;
193
+ nearbyPlacesInfo .searchLatLng = searchLatLng ;
194
+ nearbyPlacesInfo .placeList = places ;
195
+ nearbyPlacesInfo .boundaryCoordinates = boundaryCoordinates ;
196
+
197
+ // Returning closes result means we use the controller for nearby card. So no need to set search this area flags
198
+ if (!returnClosestResult ) {
199
+ // To remember latest search either around user or any point on map
200
+ latestSearchLocation = searchLatLng ;
201
+ latestSearchRadius = nearbyPlaces .radius * 1000 ; // to meter
202
+
203
+ // Our radius searched around us, will be used to understand when user search their own ___location, we will follow them
204
+ if (checkingAroundCurrentLocation ) {
205
+ currentLocationSearchRadius = nearbyPlaces .radius * 1000 ; // to meter
206
+ currentLocation = curLatLng ;
207
+ }
208
+ }
209
+ }
210
+ return nearbyPlacesInfo ;
211
+ }
212
+
121
213
/**
122
214
* Prepares Place list to make their distance information update later.
123
215
*
@@ -129,10 +221,10 @@ public NearbyPlacesInfo loadAttractionsFromLocation(final LatLng curLatLng, fina
129
221
*/
130
222
public NearbyPlacesInfo loadAttractionsFromLocation (final LatLng curLatLng ,
131
223
final LatLng searchLatLng ,
132
- final boolean returnClosestResult , final boolean checkingAroundCurrentLocation ,
133
- final boolean shouldQueryForMonuments ) throws Exception {
224
+ final boolean returnClosestResult , final boolean checkingAroundCurrentLocation )
225
+ throws Exception {
134
226
return loadAttractionsFromLocation (curLatLng , searchLatLng , returnClosestResult ,
135
- checkingAroundCurrentLocation , shouldQueryForMonuments , null );
227
+ checkingAroundCurrentLocation , null );
136
228
}
137
229
138
230
/**
@@ -171,12 +263,14 @@ public static List<BaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
171
263
172
264
/**
173
265
* Updates makerLabelList item isBookmarked value
174
- * @param place place which is bookmarked
266
+ *
267
+ * @param place place which is bookmarked
175
268
* @param isBookmarked true is bookmarked, false if bookmark removed
176
269
*/
177
270
@ MainThread
178
271
public static void updateMarkerLabelListBookmark (Place place , boolean isBookmarked ) {
179
- for (ListIterator <MarkerPlaceGroup > iter = markerLabelList .listIterator (); iter .hasNext ();) {
272
+ for (ListIterator <MarkerPlaceGroup > iter = markerLabelList .listIterator ();
273
+ iter .hasNext (); ) {
180
274
MarkerPlaceGroup markerPlaceGroup = iter .next ();
181
275
if (markerPlaceGroup .getPlace ().getWikiDataEntityId ().equals (place .getWikiDataEntityId ())) {
182
276
iter .set (new MarkerPlaceGroup (isBookmarked , place ));
0 commit comments