feat: complete reverse engineering, standard Maven structure, detailed code annotations and IoT-M platform architecture
This commit is contained in:
1 parent
e8dc09fb3c
commit
cd6a4c70e7
3045 files changed
+566733
-1
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package com.mitac.cell.map;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mitac.cell.utils.McJsonUtils;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class GeoCode {
|
||||
public static String getAddress(String apiKey, String latitude, String longitude) {
|
||||
try {
|
||||
String url = String.format("https://maps.googleapis.com/maps/api/geocode/json?latlng=%s,%s&key=%s", latitude, longitude, apiKey);
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = (new Request.Builder()).url(url).build();
|
||||
Response responses = client.newCall(request).execute();
|
||||
JsonObject jResult = (JsonObject)McJsonUtils.toJsonElement(responses.body().byteStream());
|
||||
JsonObject jInfo = jResult.getAsJsonObject("info");
|
||||
String result = null;
|
||||
if (jInfo.get("statuscode").getAsInt() == 0) {
|
||||
JsonArray jLocations = jResult.getAsJsonArray("locations");
|
||||
if (jLocations.size() > 0) {
|
||||
JsonObject jLocation = jLocations.get(0).getAsJsonObject();
|
||||
String.join(", ", jLocation.get("street").getAsString());
|
||||
result = jLocation.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (Exception var12) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user