27 lines
895 B
TypeScript
27 lines
895 B
TypeScript
import Axios from "axios";
|
|
import { ILocationCoordinates } from "./service-types/LocationTypes";
|
|
|
|
export default class NetworkService {
|
|
|
|
public static FetchWithJSONP(url: string, JSONPFunctionIdentifier: string, callback: (data: any) => any) {
|
|
const windowCallbackNamne = "bingMapLocationCallback";
|
|
const jsonPUrl = url;
|
|
|
|
(window as any)[windowCallbackNamne] = (data: any) => {
|
|
delete (window as any)[windowCallbackNamne];
|
|
document.body.removeChild(script);
|
|
callback(data);
|
|
};
|
|
|
|
var script = document.createElement("script");
|
|
script.src = jsonPUrl;
|
|
document.body.appendChild(script);
|
|
}
|
|
|
|
public static async FetchLocationData(url: string) {
|
|
const result = await Axios.get(url);
|
|
const locationResult = result.data as ILocationCoordinates;
|
|
return locationResult;
|
|
}
|
|
|
|
} |