blob: 41c308c69622079a2c75e682614b882a620a7c39 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package com.mapbox.mapboxsdk.testapp.activity.location;
import android.location.Location;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import java.util.Random;
import timber.log.Timber;
/**
* Useful utilities used throughout the testapp.
*/
public class Utils {
private static final String[] STYLES = new String[] {
Style.MAPBOX_STREETS,
Style.OUTDOORS,
Style.LIGHT,
Style.DARK,
Style.SATELLITE_STREETS
};
private static int index;
/**
* Utility to cycle through map styles. Useful to test if runtime styling source and layers transfer over to new
* style.
*
* @return a string ID representing the map style
*/
public static String getNextStyle() {
index++;
if (index == STYLES.length) {
index = 0;
}
return STYLES[index];
}
/**
* Utility for getting a random coordinate inside a provided bounds and creates a {@link Location} from it.
*
* @param bounds bounds of the generated location
* @return a {@link Location} object using the random coordinate
*/
public static Location getRandomLocation(LatLngBounds bounds) {
Random random = new Random();
double randomLat = bounds.getLatSouth() + (bounds.getLatNorth() - bounds.getLatSouth()) * random.nextDouble();
double randomLon = bounds.getLonWest() + (bounds.getLonEast() - bounds.getLonWest()) * random.nextDouble();
Location location = new Location("random-loc");
location.setLongitude(randomLon);
location.setLatitude(randomLat);
Timber.d("getRandomLatLng: %s", location.toString());
return location;
}
}
|