A super simple geo-coordinates property for Episerver

This blog post shows how to extend Episerver with a property where editors can enter an address that will be converted to latitude/longitude. It’s the latitude/longitude value that is saved. Suggestions for addresses/locations will be shown while typing.

If you want to show a location on a map you need to know the coordinates for that location. You can help the Episerver editor to edit those coordinates by creating a property where the editor can enter either coordinates (if already known), a location, an address, or anything else that the Google Maps API can convert to latitude/longitude.

This simple geo-coordinates property is using the standard auto-suggestion property editor.  The SelectionQuery that feeds the auto-suggestion property makes request to Google Maps Geocoding API to get locations and their coordinates.
You need to get an API key from Google to be able to use the API. In the example below I’ve saved the API key as an appsetting in web.config.

To make use of the auto-suggestion feature you need to decorate a string property with the AutoSuggestSelection attribute:

This is what it looks like in action

geocode

Pretty neat, if you ask me 🙂

 

At time of writing I was using Episerver 10.8.

One thought on “A super simple geo-coordinates property for Episerver

Leave a Reply