Skip to content

Commit

Permalink
feat(googlemaps): add Geocoder class (#292)
Browse files Browse the repository at this point in the history
closes #280
  • Loading branch information
ihadeed authored Jul 17, 2016
1 parent b5a2ffc commit 2996da6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/plugins/googlemaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,3 +1005,38 @@ export class GoogleMapsLatLng {
return this.lat.toFixed(precision) + ',' + this.lng.toFixed(precision);
}
}
/**
* @private
*/
export interface GeocoderRequest {
address?: string;
position?: {lat: number; lng: number};
}
/**
* @private
*/
export interface GeocoderResult {
position?: {lat: number; lng: number};
subThoroughfare?: string;
thoroughfare?: string;
locality?: string;
adminArea?: string;
postalCode?: string;
country?: string;
}
/**
* @private
*/
export class Geocoder {
/**
* Converts position to address and vice versa
* @param {GeocoderRequest} request Request object with either an address or a position
* @returns {Promise<GeocoderResult[]>}
*/
static geocode(request: GeocoderRequest): Promise<GeocoderResult[]> {
return new Promise<GeocoderResult[]>((resolve, reject) => {
if (!plugin || !plugin.google || !plugin.google.maps || !plugin.google.maps.Geocoder) reject({error: 'plugin_not_installed'});
else plugin.google.maps.Geocoder.geocode(request, resolve);
});
}
}

0 comments on commit 2996da6

Please sign in to comment.