// Gets a panorama ID from two coordinates public string CoordinatesToPanorama(string coordinates, string apiKey) { // Checks if we have API access if (!StreetViewApiEnabled) { return(null); } // Appends coordinates to panorma id string newUrl = UrlVerification + coordinates + UrlApiKey + apiKey; // Attempts to get the pano id from json found on the site string jsonStr = DownloadStreetViewValidationData(newUrl); // Gets the JSON responser object GoogleResponser g = GetJsonObject(jsonStr); // If we got null, return null string if (g == null) { return(null); } // Gets our json stuff string panoid = g.pano_id; // Final verification if (!string.IsNullOrEmpty(panoid)) { return(panoid); } return(null); }
// // Privates methods methods // private GoogleResponser GetJsonObject(string jsonStr) { // Creates object to store JSON GoogleResponser g = GoogleResponser.CreateFromJson(jsonStr); // If the status isn't OK, the coordinates have no Streetview if (g.status == "REQUEST_DENIED") { Debug.Log("Failed Google API Request: "); Debug.Log(g.error_message); throw new Exception(g.error_message); } else if (g.status == "INVALID_REQUEST") { Debug.Log("Failed Google API Request: "); Debug.Log(g.error_message); throw new Exception(g.error_message); } else if (g.status == "ZERO_RESULTS") { // This will happen pretty often so we don't // want to throw an exception, just return nulll return(null); } else if (g.status == "OK") { // This means we got the coordinates, can fully work with them return(g); } else { return(null); } }