37
37
import java .util .List ;
38
38
39
39
40
-
41
40
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback ,
42
41
GoogleApiClient .OnConnectionFailedListener {
43
42
@@ -158,22 +157,22 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
158
157
159
158
}
160
159
161
- private void init (){
160
+ private void init () {
162
161
Log .d (TAG , "init: initializing" );
163
162
164
163
mGoogleApiClient = new GoogleApiClient
165
164
.Builder (this )
166
165
.addApi (Places .GEO_DATA_API )
167
166
.addApi (Places .PLACE_DETECTION_API )
168
- .enableAutoManage (this ,this )
167
+ .enableAutoManage (this , this )
169
168
.build ();
170
169
171
170
172
171
}
173
172
174
173
175
174
public double toRadians (double deg ) {
176
- return deg * Math .PI / 180 ;
175
+ return deg * Math .PI / 180 ;
177
176
}
178
177
179
178
public double calcDist (LatLng latLng1 , LatLng latLng2 ) {
@@ -188,19 +187,16 @@ public double calcDist(LatLng latLng1, LatLng latLng2) {
188
187
double lat2R = toRadians (lat2 );
189
188
double lon2R = toRadians (lon2 );
190
189
191
- double a = Math .pow ( Math .sin ((lat2R - lat1R )/ 2 ),2 ) + Math .cos (lat1R ) * Math .cos (lat2R )* Math .pow (Math .sin ((lon2R - lon1R )/ 2 ),2 );
192
- double c = 2 * Math .atan2 (Math .sqrt (a ),Math .sqrt (1 - a ));
190
+ double a = Math .pow (Math .sin ((lat2R - lat1R ) / 2 ), 2 ) + Math .cos (lat1R ) * Math .cos (lat2R ) * Math .pow (Math .sin ((lon2R - lon1R ) / 2 ), 2 );
191
+ double c = 2 * Math .atan2 (Math .sqrt (a ), Math .sqrt (1 - a ));
193
192
double R = 6371.0 ;
194
- dist = R * c ;
193
+ dist = R * c ;
195
194
return dist ;
196
195
}
197
196
198
197
199
-
200
-
201
-
202
- private void moveCamera (LatLng latLng , float zoom , String title ){
203
- Log .d (TAG , "moveCamera: moving the camera to: lat: " + latLng .latitude + ", lng: " + latLng .longitude );
198
+ private void moveCamera (LatLng latLng , float zoom , String title ) {
199
+ Log .d (TAG , "moveCamera: moving the camera to: lat: " + latLng .latitude + ", lng: " + latLng .longitude );
204
200
mMap .moveCamera (CameraUpdateFactory .newLatLngZoom (latLng , zoom ));
205
201
206
202
MarkerOptions options = new MarkerOptions ()
@@ -210,13 +206,10 @@ private void moveCamera(LatLng latLng, float zoom, String title){
210
206
}
211
207
212
208
/**
213
- *
214
209
* CalcDist between two pars of lat-lon
215
- *
216
210
*/
217
211
218
212
219
-
220
213
LocationCallback mLocationCallback = new LocationCallback () {
221
214
@ Override
222
215
public void onLocationResult (LocationResult locationResult ) {
@@ -268,7 +261,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
268
261
//Prompt the user once explanation has been shown
269
262
ActivityCompat .requestPermissions (MapsActivity .this ,
270
263
new String []{Manifest .permission .ACCESS_FINE_LOCATION },
271
- MY_PERMISSIONS_REQUEST_LOCATION );
264
+ MY_PERMISSIONS_REQUEST_LOCATION );
272
265
}
273
266
})
274
267
.create ()
@@ -279,7 +272,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
279
272
// No explanation needed, we can request the permission.
280
273
ActivityCompat .requestPermissions (this ,
281
274
new String []{Manifest .permission .ACCESS_FINE_LOCATION },
282
- MY_PERMISSIONS_REQUEST_LOCATION );
275
+ MY_PERMISSIONS_REQUEST_LOCATION );
283
276
}
284
277
}
285
278
}
@@ -318,5 +311,4 @@ public void onRequestPermissionsResult(int requestCode,
318
311
}
319
312
320
313
321
-
322
314
}
0 commit comments