From 84c222d10bc0aecf72588e4f3032ecc658bed810 Mon Sep 17 00:00:00 2001 From: Achim Weimert Date: Thu, 5 Jul 2018 18:18:16 +0100 Subject: [PATCH] googlemaps: adapt to api changes (#26954) * add missing response status codes Added response status codes according to: https://developers.google.com/maps/documentation/javascript/places#place_details_responses * mark radarSearch as deprecated https://developers.google.com/maps/documentation/javascript/places#radar_search_requests * add new find places apis https://developers.google.com/maps/documentation/javascript/places#find_place_requests - findPlaceFromPhoneNumber() - findPlaceFromQuery() * add new fields parameter for place detail requests https://developers.google.com/maps/documentation/javascript/places#place_search_fields * add simple tests --- types/googlemaps/googlemaps-tests.ts | 25 +++++++++++++++++++++++++ types/googlemaps/index.d.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/types/googlemaps/googlemaps-tests.ts b/types/googlemaps/googlemaps-tests.ts index 99d5902a88..77a2900b7b 100644 --- a/types/googlemaps/googlemaps-tests.ts +++ b/types/googlemaps/googlemaps-tests.ts @@ -412,3 +412,28 @@ heatmap.setData([ { weight: 1, location: new google.maps.LatLng(37.782551, -122.445368) }, { weight: 2, location: new google.maps.LatLng(37.782745, -122.444586) } ]); + +/***** google.maps.places.PlacesService *****/ +let service = new google.maps.places.PlacesService(new HTMLDivElement()); + +service.getDetails({ + placeId: '-a1', + fields: ['name'] +}, (result, status) => { + if (status === google.maps.places.PlacesServiceStatus.NOT_FOUND) { + return; + } + + result.name; // $ExpectType string +}) + +service.findPlaceFromQuery({ + query: 'Big Ben London', + fields: ['name'] +}, (results, status) => { + if (status === google.maps.places.PlacesServiceStatus.ERROR) { + return; + } + + results[0].name; // $ExpectType string +}); diff --git a/types/googlemaps/index.d.ts b/types/googlemaps/index.d.ts index a8de5810ec..501dd4c1f8 100644 --- a/types/googlemaps/index.d.ts +++ b/types/googlemaps/index.d.ts @@ -1106,6 +1106,13 @@ declare namespace google.maps { zIndex?: number; } + export interface CircleLiteral extends CircleOptions { + /** The center of the Circle. */ + center?: LatLng|LatLngLiteral; + /** The radius in meters on the Earth's surface. */ + radius?: number; + } + /** * The possible positions of the stroke on a polygon. */ @@ -2549,6 +2556,8 @@ declare namespace google.maps { country: string|string[]; } + export type LocationBias = LatLng|LatLngLiteral|LatLngBounds|LatLngBoundsLiteral|Circle|CircleLiteral|string; + export interface PlaceAspectRating { rating: number; type: string; @@ -2556,6 +2565,7 @@ declare namespace google.maps { export interface PlaceDetailsRequest { placeId: string; + fields?: string[]; } export interface PlaceGeometry { @@ -2629,16 +2639,21 @@ declare namespace google.maps { export class PlacesService { constructor(attrContainer: HTMLDivElement|Map); + findPlaceFromPhoneNumber(request: FindPlaceFromPhoneNumberRequest, callback: (results: PlaceResult[], status: PlacesServiceStatus) => void): void; + findPlaceFromQuery(request: FindPlaceFromQueryRequest, callback: (results: PlaceResult[], status: PlacesServiceStatus) => void): void; getDetails(request: PlaceDetailsRequest, callback: (result: PlaceResult, status: PlacesServiceStatus) => void): void; nearbySearch(request: PlaceSearchRequest, callback: (results: PlaceResult[], status: PlacesServiceStatus, pagination: PlaceSearchPagination) => void): void; + /** @deprecated Radar search is deprecated as of June 30, 2018. After that time, this feature will no longer be available. */ radarSearch(request: RadarSearchRequest, callback: (results: PlaceResult[], status: PlacesServiceStatus) => void): void; textSearch(request: TextSearchRequest, callback: (results: PlaceResult[], status: PlacesServiceStatus, pagination: PlaceSearchPagination) => void): void; } export enum PlacesServiceStatus { + ERROR, INVALID_REQUEST, OK, OVER_QUERY_LIMIT, + NOT_FOUND, REQUEST_DENIED, UNKNOWN_ERROR, ZERO_RESULTS @@ -2693,6 +2708,18 @@ declare namespace google.maps { types?: string[]; /* Deprecated. Will be removed February 16, 2017 */ type?: string; } + + export interface FindPlaceFromQueryRequest { + fields: string[]; + locationBias?: LocationBias; + query: string; + } + + export interface FindPlaceFromPhoneNumberRequest { + fields: string[]; + locationBias?: LocationBias; + query: string; + } } /***** Drawing Library *****/