Inspired on the great "
Bloggin with XAF" video tutorial I just created a sample showing how to create a custom ListEditor to display objects in a Google Map instead on the default List View.
Using the Google Maps API this sample resolves the Longitude and Latitude of all the customers and render them on a interactive map.
You can download the source code
here.
This is how it looks like:
To embed the maps I used the free
GoogleMaps.Subgurim.NET control which allows you to integrate a Google Maps into any ASP.NET application handling with all the plumbing for you.
This is how the sample works:
- The "Customer" object implements an interface called "IPlacemark". This adds the Longitude and Latitude properties to the BO.
- Every time a "Customer" is saved it contacts the Maps API to geolocalize its address. Using the street, zip code and country the Maps API returns a Longitude and Latitude. This information is stored in two custom properties.
- A custom view called "Customers on a map" uses a custom Editor to display all the IPlacemark objects on the map.
- I used the "ViewsVariant" module to allow the user to switch between the normal view (ListView) and the (maps View)
This sample needs to be extended to use paging, error handling, converting it to a module (eg.like the scheduler module), and resolve the address in a more efficient way (only when address changes are detected).
The sample provided uses a Google Maps API key valid for the domain http://localhost:2064. If you want to change the URL you'll need a
new API Key (its free) and update the web config.
Please, drop some feedback if you find it interesting to help me improve it.