MapLocation Example

I am an Ex-VB coder getting started in Xojo by trying out some of the supplied example code. I have a question in the MapLocation sample app. I was trying to add some locations to the map on open but keep getting error messages when the browser opens. So I tried just changing the code on the button which works but can’t seem to put the code anywhere else to make this happen when the app opens. Here is the code…

Dim location As New WebMapLocation
'location.Address = LocationField.Text
location.Address = “1600 Pennsylvania Ave NW, Washington, D.C.”

LocationMap.GoToLocation(location)
LocationMap.AddLocation(location)

What am I missing?

Tough to say. The code looks OK. What error are you getting? Where is this code?

I put the code in the MapLocationPage “Open” Event Handler. I tried putting it into a method and called that. Also tried putting it into the WebMapViewer “Open” Event Handler.

Here is the error…
This application has encountered an error and cannot continue.

Could not execute returned javascript: Cannot call method ‘setStyle’ of undefined
Source: var langdir = document.getElementsByTagName(‘body’)[0]; if(langdir) { langdir.removeAttribute(‘dir’); }
var langdir = document.getElementsByTagName(‘body’)[0]; if(langdir) { langdir.setAttribute(‘lang’,‘en’); }
Xojo.controls[‘H6rdIrWc’].setStyle(null);
Xojo.controls[‘H6rdIrWc’].refresh();
Xojo.controls[‘H6rdIrWc’].setVisible(true);
Xojo.controls[‘H6rdIrWc’].refresh();
Xojo.controls[‘H6rdIrWc’].setEnabled(true);
Xojo.controls[‘H6rdIrWc’].refresh();
Xojo.controls[‘H6rdIrWc’].setCursor(‘inherit’);
Xojo.controls[‘H6rdIrWc’].refresh();
Xojo.controls[‘H6rdIrWc’].object().removeAttribute(‘title’);
Xojo.controls[‘H6rdIrWc’].refresh();
Xojo.controls[‘H6rdIrWc’].setLatitude(30.26715000000000100);
Xojo.controls[‘H6rdIrWc’].setLongitude(-97.74306000000000000);
Xojo.controls[‘H6rdIrWc’].setMapType(0);
Xojo.controls[‘H6rdIrWc’].object().style.zIndex = ‘2’;
Xojo.controls[‘H6rdIrWc’].refresh();
Xojo.controls[‘H6rdIrWc’].setZoom(8);
Xojo.controls[‘H6rdIrWc’].update(38.89783779999999800,-77.03651229999999800);

Xojo.controls[‘H6rdIrWc’].addMarker(‘Marker_273431929798’,38.89783780,-77.03651230,’’,’’,false);
new mapviewer(‘H6rdIrWc’,[]);
Xojo.controls[‘H6rdIrWc’].setEnabled(true);
Xojo.controls[‘H6rdIrWc’].setZoom(8);
Xojo.controls[‘H6rdIrWc’].setMapType(0);
Xojo.controls[‘H6rdIrWc’].googleMapInit();
new textcontrol(‘WqcQKK9Y’,[]);
Xojo.controls[‘WqcQKK9Y’].setEnabled(true);
new button(‘ZDHTYrxo’,[‘Action’]);
Xojo.controls[‘ZDHTYrxo’].setEnabled(true);
new frameworkObject(‘XOPbsd45’,[]);
Xojo.controls[‘XOPbsd45’].setEnabled(true);
Xojo.view.showPage(‘XOPbsd45’);
document.title = “Map Viewer”;

Xojo.view.dismissLoader();

Try putting it in the MapLocationPage.Shown event instead of the Open event.

MapLocationPage.Shown worked.

So… code in the MapLocationPage.Open is correct but has encountered a bug in Xojo, right?

I found another forum topic that seems to be dealing with the same problem:
Web app works with 2013r2, crashes with 2013r3
https://forum.xojo.com/5450-web-app-works-with-2013r2-crashes-with-2013r3/0

Perhaps not so much a bug as a limitation.

From the Notes for the WebPage.Open event handler in the Language Reference:

[quote]The Open event handler can be used to initialize non-visual properties and settings for controls.

In most cases, you should use the Shown event to initialize controls.[/quote]

Regarding this same example app…

I am interested in populating a map like this sample app but then giving the user features to map out driving directions between two of the locations. The built in mapping features in Xojo does not seem to have anything past adding locations, location labels and so forth. Does anyone know of additional tools that would allow me accomplish this?

I use google maps in a HTMLView to pop up directions point to point, two UK postcodes in my case, or a map of the target postcode (two radio buttons on the window.

This is in open event of the window.

  //below line gets directions between office postcode and postocde of officers home
  url="http://maps.google.co.uk/maps?f=d&source=s_d&saddr="+officepostcode+"&daddr="+mappostcode
  HTMLViewer1.LoadURL(url)

  //just the map with this line
  url="http://maps.google.co.uk/maps?f=q&hl=en&geocode=&q="+mappostcode+"&ie=UTF8&z=17&iwloc=addr&om=0"
  HTMLViewer1.LoadURL(url)

There is a scheduled feedback report

17424 - WebMapViewer - Add Directions