lookupService GooglePlacesService{@restbinding};
The @restbinding property indicates that service-access details are in your code rather than in the EGL deployment descriptor. The decision is convenient but inflexible. A change in the service location requires that you change the source code. Lesson 14 introduces the EGL deployment descriptor, where you are likely to put service-access details in most of your development work.
function checkForEnter(event Event in)
if(event.ch == 10)
search();
end
end
Consider the following background detail: The EGL runtime code invokes the checkForEnter function and passes an event object, which is a memory structure that includes details about the event. In this case, the event that caused the invocation is onKeyDown, and the event object includes the ASCII character that represents the user's keystroke. Specifically, the number 10 is the decimal value for the Carriage Return (the ENTER key) in the ASCII table, as noted here: ASCII table and description (http://www.asciitable.com).
The checkForEnter function is invoked only if the user presses a key such as Tab or ENTER when the text field has focus. The function in turn invokes the search function only if the key was ENTER. You will create the search function soon.
function buttonClicked(event Event in)
search();
end
The buttonClicked function and its relationship to the button-specific onClick property ensures that the user's clicking the Search button invokes the search function.
function search()
localMap.zoom = 10;
localMap.removeAllMarkers();
// show an initial marker, as necessary to display the map at all
localMap.addMarker(new MapMarker{ latitude = "37.47", longitude = "-122.26",
address = "I am here!", description = "San Francisco"});
// Call the remote Google service, passing the type value
call lookupService.getSearchResults( typeComboBox.value ) returning to showResults
onException displayError;
end
In this initial display for a search result set, the only detail that you provide to the localMap.addMarker() function is the city location marker.
linkListing HyperLink[0];
for(i int from 1 to retResult.result.getSize() by 1)
newLink HyperLink{padding = 4, text = retResult.result[i].name, href = "#"};
newLink.setAttribute("title", retResult.result[i].vicinity );
newLink.setAttribute("lat",
retResult.result[i].geometry.location.lat);
newLink.setAttribute("lng",
retResult.result[i].geometry.location.lng);
newLink.onClick ::= mapAddress;
linkListing.appendElement(newLink);
end
listingBox.setChildren(linkListing);
end
newLink HyperLink{padding = 4, text = retResult.result[i].title, href = "#"};
The hyperlink will cause the invocation of code rather than a web address. However, the presence of the placeholder ensures that the hyperlink shows text in a familiar way, with an underscore and in color, as if the user's clicking the hyperlink opens a web site.
function mapAddress(e Event in)
// Show the marker when the user clicks the link
businessAddress string = e.widget.getAttribute("address") as string;
businessName string = e.widget.getAttribute("title") as string;
lat string = e.widget.getAttribute("lat") as string;
lng string = e.widget.getAttribute("lng") as string;
localMap.addMarker( new MapMarker{ latitude = lat,
longitude = lng, address = businessAddress, description = businessName});
End
When the user clicks the hyperlink at run time, the mapAddress function retrieves the attributes that were set in the showResults function and sets a marker on the displayed map.
function displayError(ex AnyException in)
DojoDialogLib.showError("Google Service",
"Cannot invoke Google Places service: " + ex.message, null);
end
DojoDialogLib is a Library part in the com.ibm.egl.rui.dojo.samples project that you added to your workspace in Lesson 2. The showError function in that library displays information in a dialog. The function invocation includes a string named message, which is in the exception record that the EGL runtime code passes to the displayError function.
Because this portlet works independently, you can test it separately.

localMap.removeAllMarkers();
In the next lesson, you embed the new handler in the application.