|
| 1 | +# Place Map |
| 2 | + |
| 3 | +Place Maps are a way to easily show geolocated objects on a Google Map : |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Configuration |
| 8 | + |
| 9 | +Make sur you have the prerequisites: |
| 10 | +- update the `GOOGLE_API_KEY` system parameter after [generating it with a Google Account](https://developers.google.com/maps/documentation/javascript/get-api-key) |
| 11 | +- have a **geographical coordinates attribute** setup on your object (if working with an adress, you might have to use some tool to transform the address into coordinates, see the following example from the demo using a google maps tool and also requires a working Google API key) |
| 12 | + |
| 13 | +And proceed to configure the placemap. You can configure up to 3 labels that will show up when clicking on a pin, the first one being considerend a title. |
| 14 | + |
| 15 | +## Geocoding address |
| 16 | + |
| 17 | +```java |
| 18 | +/** Hook override: geo-locate from address fields */ |
| 19 | +@Override |
| 20 | +public String preSave() { |
| 21 | + if (isMainInstance()) { // Only done for the main UI instance |
| 22 | + try { |
| 23 | + // Geocode address fields |
| 24 | + ObjectField coords = getField("demoCliCoords"); |
| 25 | + ObjectField a1 = getField("demoCliAddress1"); |
| 26 | + ObjectField a2 = getField("demoCliAddress2"); |
| 27 | + ObjectField zc = getField("demoCliZipCode"); |
| 28 | + ObjectField ci = getField("demoCliCity"); |
| 29 | + ObjectField co = getField("demoCliCountry"); |
| 30 | + |
| 31 | + if (coords.isEmpty() || a1.hasChanged() || a2.hasChanged() || zc.hasChanged() || ci.hasChanged() || co.hasChanged()) { |
| 32 | + String a = a1.getValue() + (a2.isEmpty() ? "" : ", " + a2.getValue()) + ", " + zc.getValue() + ", " + ci.getValue() + ", " + co.getValue(); |
| 33 | + Location c = new GMapTool(getGrant()).geocodeOne(a); |
| 34 | + coords.setValue(c == null ? "" : c.toString()); |
| 35 | + } |
| 36 | + } catch (Exception e) { |
| 37 | + AppLog.warning(null, e, getGrant()); |
| 38 | + } |
| 39 | + } |
| 40 | + return super.preSave(); |
| 41 | +} |
| 42 | +``` |
0 commit comments