Skip to content

Commit

Permalink
feat: additional types
Browse files Browse the repository at this point in the history
  • Loading branch information
skynet2 committed Feb 3, 2018
1 parent 10b0457 commit 977f059
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 26 deletions.
12 changes: 11 additions & 1 deletion example/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { Component, ViewChild } from '@angular/core';
import { GooglePlaceDirective } from "../../src/ngx-google-places-autocomplete.directive";
import { ComponentRestrictions } from "../../src/objects/options/componentRestrictions";
import { Address } from "../../src/objects/address";

@Component({
selector: 'my-app',
template: `<input ngx-google-places-autocomplete #places="ngx-places"/><button (click)="changeConfig()">Change Config</button><button (click)="search()">Execute search</button>`,
template: `<input ngx-google-places-autocomplete #places="ngx-places" (onAddressChange)="onChange($event)" />
<button (click)="changeConfig()">Change Config</button>
<button (click)="search()">Execute search</button>`,
})
export class AppComponent {
@ViewChild('places') places: GooglePlaceDirective;

public onChange(address: Address) {
console.log(address.geometry.location.lng());
console.log(address.geometry.location.lat());
console.log(address.geometry.location.toJSON());
console.log(address.geometry.viewport.getNorthEast());
}

public changeConfig() {
this.places.options.componentRestrictions = new ComponentRestrictions({
country: "UA"
Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Demo</title>
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>

<script src="https://maps.googleapis.com/maps/api/js?key=<key>&libraries=places&sensor=false&language=en-US&region=us"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-google-places-autocomplete",
"version": "1.0.5",
"version": "2.0.0",
"scripts": {
"start": "tsc -p example && tsc -p src && concurrently \"tsc -p example -w\" \"tsc -p src -w\" \"lite-server --config sync-bs-config.json\" ",
"yarn": "yarn",
Expand Down Expand Up @@ -33,11 +33,11 @@
}
],
"peerDependencies": {
"@angular/core": ">= 4.0.0"
"@angular/core": ">= 2.0.0"
},
"devDependencies": {
"@angular/common": "4.0.0",
"@angular/core" : "4.0.0",
"@angular/core": "4.0.0",
"@angular/compiler": "4.0.0",
"@angular/compiler-cli": "4.0.0",
"@angular/platform-browser": "4.0.0",
Expand All @@ -55,6 +55,6 @@
"rimraf": "^2.6.2",
"@ngtools/webpack": "^1.8.5",
"rollup": "0.41.4",
"rollup-plugin-copy" : "0.2.3"
"rollup-plugin-copy": "0.2.3"
}
}
17 changes: 13 additions & 4 deletions src/objects/address.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import { AddressComponent } from "./addressComponent";
import { Geometry } from "./geometry";
import { Photo } from "./photo";
import { OpeningHours } from "./openingHours";
import { PlaceReview } from "./placeReview";

export class Address {
address_components: AddressComponent[];
adr_address: string;
formatted_address: string;
formatted_phone_number: string;
geometry: Geometry;
html_attributions: string[];
icon: string;
id: string;
international_phone_number: string;
name: string;
opening_hours: OpeningHours;
permanently_closed: boolean;
photos: Photo[];
place_id: string;
reference: string;
scope: string;
price_level: number;
rating: number;
reviews: PlaceReview[];
types: string[];
url: string;
utc_offset: number;
vicinity: string;
html_attributions: any[];

website: string;
}
8 changes: 4 additions & 4 deletions src/objects/geometry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Viewport } from "./viewport";
import { Location } from "./location";
import { LatLngBounds } from "./latLngBounds";
import { LatLng } from "./latLng";

export interface Geometry {
location: Location;
viewport: Viewport;
location: LatLng;
viewport: LatLngBounds;
}
16 changes: 16 additions & 0 deletions src/objects/latLng.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface LatLng {
/** Comparison function. */
equals(other: LatLng): boolean;
/** Returns the latitude in degrees. */
lat(): number;
/** Returns the longitude in degrees. */
lng(): number;
/** Converts to string representation. */
toString(): string;
/** Returns a string of the form "lat,lng". We round the lat/lng values to 6 decimal places by default. */
toUrlValue(precision?: number): string;
/** Converts to JSON representation. This function is intended to be used via JSON.stringify. */
toJSON(): LatLngLiteral;
}
export type LatLngLiteral = { lat: number; lng: number }
export type LatLngBoundsLiteral = { east: number; north: number; south: number; west: number }
49 changes: 49 additions & 0 deletions src/objects/latLngBounds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* A LatLngBounds instance represents a rectangle in geographical coordinates, including one
* that crosses the 180 degrees longitudinal meridian.
*/
import { LatLng, LatLngBoundsLiteral, LatLngLiteral } from "./latLng";

export interface LatLngBounds {
/** Returns true if the given lat/lng is in this bounds. */
contains(latLng: LatLng | LatLngLiteral): boolean;

/** Returns true if this bounds approximately equals the given bounds. */
equals(other: LatLngBounds | LatLngBoundsLiteral): boolean;

/** Extends this bounds to contain the given point. */
extend(point: LatLng | LatLngLiteral): LatLngBounds;

/** Computes the center of this LatLngBounds */
getCenter(): LatLng;

/** Returns the north-east corner of this bounds. */
getNorthEast(): LatLng;

/** Returns the south-west corner of this bounds. */
getSouthWest(): LatLng;

/** Returns true if this bounds shares any points with the other bounds. */
intersects(other: LatLngBounds | LatLngBoundsLiteral): boolean;

/** Returns if the bounds are empty. */
isEmpty(): boolean;

/** Converts to JSON representation. This function is intended to be used via JSON.stringify. */
toJSON(): LatLngBoundsLiteral;

/** Converts the given map bounds to a lat/lng span. */
toSpan(): LatLng;

/** Converts to string. */
toString(): string;

/**
* Returns a string of the form "lat_lo,lng_lo,lat_hi,lng_hi" for this bounds, where "lo" corresponds to the
* southwest corner of the bounding box, while "hi" corresponds to the northeast corner of that box.
*/
toUrlValue(precision?: number): string;

/** Extends this bounds to contain the union of this and the given bounds. */
union(other: LatLngBounds | LatLngBoundsLiteral): LatLngBounds;
}
4 changes: 0 additions & 4 deletions src/objects/location.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/objects/openingHours.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export interface OpeningHours {
open_now: boolean;
periods: OpeningPeriod[];
weekday_text: string[];
}

export interface OpeningPeriod {
open: OpeningHoursTime;
close?: OpeningHoursTime;
}

export interface OpeningHoursTime {
day: number;
hours: number;
minutes: number;
nextDate: number;
time: string;
}
4 changes: 2 additions & 2 deletions src/objects/options/options.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Viewport } from "../viewport";
import { LatLngBounds } from "../latLngBounds";
import { ComponentRestrictions } from "./componentRestrictions";

export class Options {
public bounds: Viewport;
public bounds: LatLngBounds;
public componentRestrictions: ComponentRestrictions;
public types: string[];

Expand Down
5 changes: 5 additions & 0 deletions src/objects/photo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Photo {
height: number;
html_attributions: string[];
width: number;
}
12 changes: 12 additions & 0 deletions src/objects/placeReview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface PlaceReview {
aspects: PlaceAspectRating[];
author_name: string;
author_url: string;
language: string;
text: string;
}

export interface PlaceAspectRating {
rating: number;
type: string;
}
6 changes: 0 additions & 6 deletions src/objects/viewport.ts

This file was deleted.

0 comments on commit 977f059

Please sign in to comment.