-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use google maps api to support secure requests (#311)
Co-authored-by: Konstantinos Stratis <[email protected]> Co-authored-by: Stephan Meijer <[email protected]>
- Loading branch information
1 parent
73b66cc
commit 50953a6
Showing
14 changed files
with
419 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
name: LegacyGoogle | ||
menu: Providers | ||
route: /providers/legacy-google | ||
--- | ||
|
||
import Playground from '../components/Playground'; | ||
import Map from '../components/Map'; | ||
|
||
# Legacy Google Provider | ||
|
||
**<u>WARNING</u>: This provider is unsafe to use and should be considered <u>DEPRECATED</u>. | ||
It is strongly suggested to use the new [Google Provider][4]. If you're currently migrating from a previous version | ||
and you still wish to use this provider you should pull in the `LegacyGoogleProvider` class | ||
and rename your references accordingly.** | ||
|
||
**note**: Google services require an API key. [Obtain here][1]. | ||
For more options and configurations, see the [Google Maps developer docs][2]. | ||
|
||
<Playground> | ||
<Map provider="Google" /> | ||
</Playground> | ||
|
||
```js | ||
import { LegacyGoogleProvider } from 'leaflet-geosearch'; | ||
|
||
const provider = new LegacyGoogleProvider({ | ||
params: { | ||
key: '__YOUR_GOOGLE_KEY__', | ||
}, | ||
}); | ||
|
||
// add to leaflet | ||
import { GeoSearchControl } from 'leaflet-geosearch'; | ||
|
||
map.addControl( | ||
new GeoSearchControl({ | ||
provider, | ||
style: 'bar', | ||
}), | ||
); | ||
``` | ||
|
||
## Optional parameters | ||
|
||
Google supports a number of [optional parameters][3]. As Google requires those parameters to be added to the url, they can be added to the `params` key of the provider. | ||
|
||
All options defined next to the `params` key, would have been added to the request body. | ||
|
||
```js | ||
const provider = new LegacyGoogleProvider({ | ||
params: { | ||
key: '__YOUR_GOOGLE_KEY__', | ||
language: 'nl', // render results in Dutch | ||
region: 'nl', // prioritize matches within The Netherlands | ||
}, | ||
}); | ||
``` | ||
|
||
[1]: https://developers.google.com/maps/documentation/javascript/get-api-key | ||
[2]: https://developers.google.com/maps/documentation/geocoding/start | ||
[3]: https://developers.google.com/maps/documentation/geocoding/intro#geocoding | ||
[4]: /providers/google |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const geocoderGeocoderResponse: google.maps.GeocoderResult = { | ||
address_components: [ | ||
{ | ||
long_name: '1', | ||
short_name: '1', | ||
types: ['street_number'], | ||
}, | ||
{ | ||
long_name: 'George Maduroplein', | ||
short_name: 'George Maduroplein', | ||
types: ['route'], | ||
}, | ||
{ | ||
long_name: 'Scheveningen', | ||
short_name: 'Scheveningen', | ||
types: ['political', 'sublocality', 'sublocality_level_1'], | ||
}, | ||
{ | ||
long_name: 'Den Haag', | ||
short_name: 'Den Haag', | ||
types: ['locality', 'political'], | ||
}, | ||
{ | ||
long_name: 'Den Haag', | ||
short_name: 'Den Haag', | ||
types: ['administrative_area_level_2', 'political'], | ||
}, | ||
{ | ||
long_name: 'Zuid-Holland', | ||
short_name: 'ZH', | ||
types: ['administrative_area_level_1', 'political'], | ||
}, | ||
{ | ||
long_name: 'Netherlands', | ||
short_name: 'NL', | ||
types: ['country', 'political'], | ||
}, | ||
{ | ||
long_name: '2584 RZ', | ||
short_name: '2584 RZ', | ||
types: ['postal_code'], | ||
}, | ||
], | ||
formatted_address: 'George Maduroplein 1, 2584 RZ Den Haag, Netherlands', | ||
geometry: { | ||
location: { | ||
toJSON: () => { | ||
return { | ||
lat: 52.0994757, | ||
lng: 4.2969304, | ||
} as google.maps.LatLngLiteral; | ||
}, | ||
} as google.maps.LatLng, | ||
location_type: 'ROOFTOP' as google.maps.GeocoderLocationType.ROOFTOP, | ||
viewport: { | ||
toJSON: () => { | ||
return { | ||
north: 52.1008246802915, | ||
east: 4.298279380291502, | ||
south: 52.0981267197085, | ||
west: 4.295581419708498, | ||
} as google.maps.LatLngBoundsLiteral; | ||
}, | ||
} as google.maps.LatLngBounds, | ||
}, | ||
place_id: 'ChIJx9INHE23xUcRQLyRyK-B_sw', | ||
types: [ | ||
'amusement_park', | ||
'establishment', | ||
'point_of_interest', | ||
'tourist_attraction', | ||
], | ||
}; | ||
|
||
export default geocoderGeocoderResponse; |
Oops, something went wrong.