Skip to content

Commit 2fd3921

Browse files
authoredNov 6, 2023
feat: added street view source parameter to fetchStreetViewData (#1262)
1 parent 233089a commit 2fd3921

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed
 

‎README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ Full guides for using the utilities are published in
110110
The StreetViewUtil class provides functionality to check whether a location is supported in StreetView. You can avoid errors when [adding a Street View panorama](https://developers.google.com/maps/documentation/android-sdk/streetview) to an Android app by calling this metadata utility and only adding a Street View panorama if the response is `OK`.
111111

112112
```kotlin
113-
StreetViewUtils.fetchStreetViewData(LatLng(8.1425918, 11.5386121), BuildConfig.MAPS_API_KEY)
113+
StreetViewUtils.fetchStreetViewData(LatLng(8.1425918, 11.5386121), BuildConfig.MAPS_API_KEY,Source.DEFAULT)
114114
```
115115

116116
`fetchStreetViewData` will return `NOT_FOUND`, `OK`, `ZERO_RESULTS` or `REQUEST_DENIED`, depending on the response.
117117

118+
By default, the `Source` is set to `Source.DEFAULT`, but you can also specify `Source.OUTDOOR` to request outdoor Street View panoramas.
119+
118120
</details>
119121

120122
<details>

‎library/src/main/java/com/google/maps/android/StreetViewUtil.kt

+22-6
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,26 @@ class StreetViewUtils {
3535
/**
3636
* This function will check whether a location is available on StreetView or not.
3737
*
38-
* @param latLng Location to check
39-
* @param apiKey Maps API Key
38+
* @param latLng The `LatLng` object representing the location for which you want to fetch Street View data.
39+
* @param apiKey The API key for Google Maps services.
40+
* @param source The source of the Street View panorama. It is optional parameter and default value is `Source.DEFAULT`
41+
* - `Source.DEFAULT`: Use the default Street View source.
42+
* - `Source.OUTDOOR`: Use the outdoor Street View source.
4043
* @return A Status value specifying if the location is available on Street View or not,
4144
* whether the used key is a right one, or any other error.
4245
*/
43-
suspend fun fetchStreetViewData(latLng: LatLng, apiKey: String): Status {
44-
val urlString =
45-
"https://maps.googleapis.com/maps/api/streetview/metadata?location=${latLng.latitude},${latLng.longitude}&key=$apiKey"
46+
suspend fun fetchStreetViewData(
47+
latLng: LatLng,
48+
apiKey: String,
49+
source: Source = Source.DEFAULT
50+
): Status {
51+
52+
val urlString = buildString {
53+
append("https://maps.googleapis.com/maps/api/streetview/metadata")
54+
append("?location=${latLng.latitude},${latLng.longitude}")
55+
append("&key=$apiKey")
56+
append("&source=${source.value}")
57+
}
4658

4759
return withContext(Dispatchers.IO) {
4860
try {
@@ -72,7 +84,6 @@ class StreetViewUtils {
7284
val jsonObject = JSONObject(responseString)
7385
val statusString = jsonObject.optString("status")
7486
val status = Status.valueOf(statusString)
75-
7687
return ResponseStreetView(status)
7788
}
7889
}
@@ -89,3 +100,8 @@ enum class Status {
89100
INVALID_REQUEST,
90101
UNKNOWN_ERROR
91102
}
103+
104+
enum class Source(var value: String) {
105+
DEFAULT("default"),
106+
OUTDOOR("outdoor");
107+
}

0 commit comments

Comments
 (0)
Please sign in to comment.