# Using the Google Maps Extended Control

> Source: https://manual.pvxplus.com/extended-nomads-objects/google-maps-interface/using-the-google-maps-extended-control

## Example 1: Displaying a Map, Markers, Info Windows and Geocoding

To add a Google Map to your application panel, follow these steps to create an **[External Control](https://manual.pvxplus.com/nomads-graphical-application/creating-panel-controls/com-control/com-control)** using the **[NOMADS Panel Designer](https://manual.pvxplus.com/nomads-graphical-application/panel-designer/introduction)**:

|  |  |
| --- | --- |
| 1\. | Select the *External Control* from the **Controls Toolbar** and outline the location of the map on the panel. |
| 2\. | In the **External Control Properties** window, enter an *Object Name* for the control (e.g. MAP). |
| 3\. | Click the *Ext. Control* query button and select *PVX Plus Controls* from the popup menu. |
| 4\. | From the list that displays, select *Google Maps Control*. |
| 5\. | In the **External Control Properties** window, click the **Properties** tab to set the properties. |
|  | ![](https://manual.pvxplus.com/migration-assets/a30da6a98b5e73590a53f6b31a60a5fc4cd2ba87d06e0301823146f7fdea64a9.jpg) |
|  | Four properties are ***required*** when defining a map:<br>\|  \|  \|  \|<br>\| --- \| --- \| --- \|<br>\|  \| *latitude* \| Latitude in degrees of the center point of the map. Range is -90 to 90 degrees. \|<br>\|  \| *longitude* \| Longitude in degrees of the center point of the map. Range wraps from -180 to 180 degrees. \|<br>\|  \| *mapTypeId* \| Type of map to be displayed. Options are *hybrid, roadmap, satellite* and *terrain*. \|<br>\|  \| *zoom* \| Numeric zoom factor for the map (zero-based). \|<br>\| Other properties are optional; however, if an API Key has been obtained, it can be set either in the **[APIkey](https://manual.pvxplus.com/extended-nomads-objects/google-maps-interface/map-events-methods-properties#apikey)** property or by setting the **%GoogleAPIkey$** variable. See **[Adding a Google Maps API Key](https://manual.pvxplus.com/extended-nomads-objects/google-maps-interface/adding-google-maps-api-key)**. \|  \|  \| |
| 6\. | Save the definition. This information is sufficient to display the map on your panel, complete with map type and zoom controls, as well as full standard Google Map UI capability, including full mouse and keyboard control. |
| Now add some controls and logic to see some of the functionality available in Google Maps, such as adding/removing markers and info windows, along with geocoding that translates human-readable addresses into latitude/longitude locations and vice versa. |  |
| 7\. | Add three multi-lines: *Address, Latitude* and *Longitude*, as well as fonted text prompts to accompany them. Set the *Numeric* attribute for the *Latitude* and *Longitude* multi-lines. |
| 8\. | You will need more than standard precision to handle Latitude and Longitude values. Set *Precision* to 6 on the **Display** tab of the **Header Panel Definition** window. |
| 9\. | Add a *Geocode_Address* button, a *Geocode_Location* button and a *Close* button to exit the panel.<br>Set the OnChange logic on the **Logic** tab for the *Close* button to *End*.<br>Set the OnChange logic on the **Logic** tab for the *Geocode_Address* button to *Execute:*<br>```<br>location$=map.ctl'geocode$(address$);<br>latitude=map.ctl'geocodeLatitude;<br>longitude=map.ctl'geocodeLongitude;<br>map.ctl'addMarker(latitude,longitude,location$)<br>``` |
|  | When the button is pushed, the address is passed to the geocode method, which returns the latitude and longitude as a string with a comma separator. The geocoder also loads the **[geocodeLatitude](https://manual.pvxplus.com/extended-nomads-objects/google-maps-interface/map-events-methods-properties#geocodelat)** and **[geocodeLongitude](https://manual.pvxplus.com/extended-nomads-objects/google-maps-interface/map-events-methods-properties#geocodelong)** properties, which are used in this case to populate the *Latitude* and *Longitude* multi-lines. A marker is then created using the given latitude and longitude, and the location is used as the marker title, which is displayed as the marker tip.<br>![](https://manual.pvxplus.com/migration-assets/f05b6fd3c4961236d68d6fd9e1c47fee08b6aca5d4375e20476e87342065728c.jpg) |
|  | Set the OnChange logic on the **Logic** tab for the *Geocode_Location* button to *Execute:* |
|  | ```<br>address$=map.ctl'geocode$(latitude,longitude,0);<br>map.ctl'showInfoWindow(latitude,longitude,address$)<br>``` |
|  | When the button is pushed, the latitude, longitude and level are passed to the geocode method. The level indicates how specific or general the returned address is to be, with 0 being the most specific address. The address is then displayed in an info window placed at the given latitude and longitude.<br>![](https://manual.pvxplus.com/migration-assets/e9ccfde17caeefe87d8944f37af737686981d517c4f422b1e2de5fb900c127a3.jpg) |
| 10\. | Finally, click the **Properties** tab in the **External Control Properties** window. Set the *markerclick Event* logic to *Execute:*<br>```<br>markerid=map.ctl'clickmarker;<br>map.ctl'removeMarker(markerid)<br>``` |
|  | When a marker is clicked, it is removed from the map.<br>![](https://manual.pvxplus.com/migration-assets/cacf3a385c8588b06833e8b23e2be65d647bf85ebb9dc9543aa8037b195ebbee.jpg) |

This example shows just a few of the properties, methods and events available to the Google Maps Extended Control.

For additional information, visit the Google Maps Web site: **[http://code.google.com/apis/maps/documentation/v3/](http://code.google.com/apis/maps/documentation/v3/)**.

## Example 2: Requesting Directions

|  |  |
| --- | --- |
| 1\. | Using the methodology described in the first example, create a new application panel in the NOMADS Panel Designer and add a Google Map extended control with the name DIRECTIONS. |
| 2\. | In addition to the four properties *(latitude, longitude, mapTypeID* and *zoom)* required to display a map, two other properties must be set to request directions, *showDirectionsPane* and *directionsPanePercent*:<br>\|  \|  \|<br>\| --- \| --- \|<br>\| *showDirectionsPane* \| Used to enable the directions service and indicate the placement of the directions. Values are:<br>0<br>Directions service not enabled. ***(Default)***<br>1<br>Directions service enabled. Directions are displayed to the *left* of the map.<br>2<br>Directions service enabled. Directions are displayed to the *right* of the map. \|<br>\| *directionsPanePercent* \| Percent (0 - 100) of the designated horizontal map area to be used to display directions. If set to 0, then a default value of 30 will be used. \| |
|  | These properties must be set in the map definition and cannot be changed dynamically.<br>In this example, the following settings are used: *latitude* = 44, *longitude* = -79, *zoom* = 8, and the default setting for *mapTypeid(hybrid)*. The *showDirectionsPane* property has been set to 1 to display directions to the left of the map, and *directionsPanePercent* has been set to 33, setting the directions display to occupy 33% of the width allotted for the map. |
|  | There are many directions-related properties.<br>![](https://manual.pvxplus.com/migration-assets/41bca8cb58cd03ac48583ac9c55f2c55b45e45764da221ab5b17a1c4e4af8e3f.jpg) |
|  | ```<br>The following properties are used as parameters for directions requests:<br>          directionsAvoidHighways<br>          directionsAvoidTolls<br>          directionsOptimizeWaypoints<br>          directionsProvideRouteAlternatives<br>          directionsRegion$<br>          directionsTravelMode$<br>          directionsUnitSystem$<br>``` |
|  | ```<br>These properties are display options:<br>          directionsDraggable<br>          directionsHideRouteList<br>          directionsPreserveViewport<br>          directionsRouteColor$<br>          directionsRouteColour$<br>          directionsRoutePixels<br>          directionsRouteOpacity<br>          directionsSuppressBicyclingLayer<br>          directionsSuppressInfoWindows<br>          directionsSuppressMarkers<br>          directionsSuppressPolylines<br>``` |
|  | When set, the above properties will affect any subsequent directions requests; they have no effect on currently displayed directions. These properties may be set in the map definition or any time prior to making a directions request.  <br>  <br>See **[Directions-Related Properties](https://manual.pvxplus.com/extended-nomads-objects/google-maps-interface/directions-related-properties-and-methods#properties)**. |
| Now add some controls and logic to generate directions. |  |
| 3\. | Add three multi-lines: *Origin, Stopover* and *Destination*, as well as fonted text prompts to accompany them.<br>Two locations, an origin and destination, are required to request directions. These may be in the form of an address or as latitude/longitude pairs. Addresses are used in this example. Stopover locations, or waypoints, are optional. This example has one stopover; however, up to 8 are allowed (23 waypoints for Google Maps API Premier customers). |
| 4\. | Add a *Get_Directions* button and a *Close* button to exit the panel.  <br>  <br>Set the OnChange logic for the *Close* button to *End*.  <br>  <br>Set the OnChange logic for the *Get_Directions* button to *Execute:*<br>```<br>directions.ctl'clearDirections();<br>directions.ctl'clearWaypoints();<br>if stopover$<>"" \<br>     then directions.ctl'addWaypoint(1,stopover$) \<br>end_if ;<br>status$=directions.ctl'getDirections$(origin$,destination$)<br>```<br>When the button is pushed, any directions currently on the map are cleared, as are any waypoints that have been defined. This is necessary due to the design of the sample panel, which allows multiple directions requests for different origins, destinations and waypoints. |
| 5\. | Then, the optional waypoint is added. Waypoints are additional locations through which the calculated route must pass. In this case, a single waypoint is added with 1 representing the sequence number. Multiple waypoints are possible, where, by default, the route follows the order of the waypoint sequence numbers. In addition, by default, waypoints are stopover points, which divide the route into legs.  <br>  <br>You can specify that waypoints are not stopovers *(addWaypoint(sequence, address, stopoverFlag)* where *stopoverFlag=0)*, in which case they are marked on the route with a *dot* and do not divide the route into legs. If all waypoints are stopovers, then the **[directionsOptimizeWaypoints](https://manual.pvxplus.com/extended-nomads-objects/google-maps-interface/directions-related-properties-and-methods#optimize)** property can be turned ***On***, in which case the sequence of the waypoints is ignored and an optimal route determined. |
| 6\. | Finally, the **[getDirections$()](https://manual.pvxplus.com/extended-nomads-objects/google-maps-interface/directions-related-properties-and-methods#getdirections)** method is passed the *Origin* and *Destination.* Based upon these values and previously set values, such as waypoints and the various directions-related properties, a route is drawn on the map and directions displayed in the *directions* pane. As well, the method returns a status to indicate whether the method was successful ("OK") or not. |
|  | ![](https://manual.pvxplus.com/migration-assets/6a471d9acc98070ce9e880b1ffbdb58781505f35478b39646bcea7f646f65f62.jpg) |

## See Also

**[Directions-Related Methods](https://manual.pvxplus.com/extended-nomads-objects/google-maps-interface/directions-related-properties-and-methods#methods)**
