UNPKG

nativescript-plugin-google-places

Version:
137 lines 5.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var utils = require("tns-core-modules/utils/utils"); var Common = require("./plugin-google-places.common"); ; ; function init() { GMSPlacesClient.provideAPIKey("__API_KEY__"); GMSServices.provideAPIKey("__API_KEY__"); } exports.init = init; function pickPlace(viewport) { return PlacePicker.Instance.pickPlace(viewport); } exports.pickPlace = pickPlace; function getPlacesById(ids) { return new Promise(function (resolve, reject) { var client = GMSPlacesClient.sharedClient(); var places = []; var getPlacesRecursive = function () { if (ids.length === 0) { resolve(places); } else { client.lookUpPlaceIDCallback(ids.shift(), function (place, error) { if (!place) { reject(error); } else { places.push({ name: place.name, id: place.placeID, address: place.formattedAddress, attributions: place.attributions, types: utils.ios.collections.nsArrayToJSArray(place.types) }); } getPlacesRecursive(); }); } }; getPlacesRecursive(); }); } exports.getPlacesById = getPlacesById; function getStaticMapUrl(place, options) { return Common.getStaticMapUrl(place.address, options); } exports.getStaticMapUrl = getStaticMapUrl; function getStaticMapUrlByAddress(address, options) { return Common.getStaticMapUrl(address, options); } exports.getStaticMapUrlByAddress = getStaticMapUrlByAddress; ; ; ; var PlacePicker = (function (_super) { __extends(PlacePicker, _super); function PlacePicker() { return _super.call(this) || this; } Object.defineProperty(PlacePicker, "Instance", { get: function () { if (!this._instance) { this._instance = PlacePicker.new(); this._instance.initialize(); } return this._instance; }, enumerable: true, configurable: true }); PlacePicker.prototype.pickPlace = function (viewport) { var _this = this; var bounds = null; if (viewport) { var northEast = new CLLocationCoordinate2D(); northEast.latitude = viewport.northEast.latitude; northEast.longitude = viewport.northEast.longitude; var southWest = new CLLocationCoordinate2D(); southWest.latitude = viewport.southWest.latitude; southWest.longitude = viewport.southWest.longitude; bounds = GMSCoordinateBounds.alloc().initWithCoordinateCoordinate(southWest, northEast); } var config = GMSPlacePickerConfig.alloc().initWithViewport(bounds); this.placePickerViewController.initWithConfig(config); var rootViewController = utils.ios.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController; rootViewController.presentViewControllerAnimatedCompletion(this.placePickerViewController, true, null); return new Promise(function (resolve, reject) { _this.setPromise(resolve, reject); }); }; PlacePicker.prototype.initialize = function () { this.placePickerViewController = GMSPlacePickerViewController.alloc().initWithConfig(null); this.placePickerViewController.delegate = this; }; PlacePicker.new = function () { return _super.new.call(this); }; PlacePicker.prototype.placePickerDidPickPlace = function (placePicker, place) { this.destroyPlacePicker(); if (this.resolve) { this.resolve({ name: place.name, id: place.placeID, address: place.formattedAddress, attributions: place.attributions, types: utils.ios.collections.nsArrayToJSArray(place.types) }); } }; PlacePicker.prototype.placePickerDidFailWithError = function (placePicker, error) { this.destroyPlacePicker(); if (this.reject) { this.reject(error); } }; PlacePicker.prototype.placePickerDidCancel = function (placePicker) { this.destroyPlacePicker(); if (this.resolve) { this.resolve(null); } }; PlacePicker.prototype.setPromise = function (resolve, reject) { this.resolve = resolve; this.reject = reject; }; PlacePicker.prototype.destroyPlacePicker = function () { var rootViewController = utils.ios.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController; rootViewController.dismissViewControllerAnimatedCompletion(true, null); PlacePicker._instance = null; }; return PlacePicker; }(NSObject)); PlacePicker._providedKeys = false; PlacePicker.ObjCProtocols = [GMSPlacePickerViewControllerDelegate]; //# sourceMappingURL=plugin-google-places.ios.js.map