And so, all I have decided to revisit the example. This time however we will create a custom input control, and the user will click on the map to show where they are located. These might be useful in an emergency situation, or something far more mundane such as simply be able to say what your address is, quickly.
- Marker on the map to display their browser-reported location (seen previously)
- Information window to display text (seen previously)
- From the latitude and longitude obtain the Street Address
- The possibility to drag the marker to another location if incorrect
- A button to confirm the selection of the address
- The chosen the address will be passed to an attribute in the Project
In this example therefore, we will need to use reverse geocoding. Specifically, we need to convert the latitude and longitude into an address. Using this Google service will normally provide us with a close match. There may be multiple matches, or indeed no match at all.
For simplicity we will only handle the case where at least one match is found, and we will take the first match which is typically the closest. We will not look at the other cases where there are multiple choices. We are reserving that for another post in a little bit!
In the example provided, which is as usual for education and amusement purposes only, the information from Google goes to our interview and is passed into an attribute. Of course, what happens after that, it’s you that decides!
To keep things simple, the initial part of the script is the same. We use your location to plant the marker on the map. The exact icon used, depends entirely on what you chose in the interview : we used a simple example where the user declares an accident or a fire or some other emergency. The marker is planted on the map. Then we introduce drag and dragend handlers, as well as a click handler.
The first page of the Interview is shown below.
Then we have a typical page displaying only a single Input Control for our demo.
Our code will handle a few events. The marker click handler will display the address of the location in an infowindow. The drag and dragend handlers manage the user dragging the marker to a new location: maybe they didn’t get it right first time, so we let them do it again.
The two main functions in this code are the confirm_my_address function, which lets the user click a button in the marker and pass the address to Oracle Policy Automation to confirm that the marker is in the correct location, and the geocodeLatLng function, which does exactly what it says.
Enjoy the video and if you are interested, you can download the code example for free, with no warranties and just for fun, from the OPA Hub Shop as usual. Remember to use Ctrl+F5 to run it in a real browser.