[Google Maps] Can't add directions

[Google Maps] Can't add directions

  
Forge Component
(14)
Published on 4 Oct by OutSystems Labs
14 votes
Published on 4 Oct by OutSystems Labs
Hey folks, 
I have a WebScreen that has a RouteMap, three inputs (Duration, Origin, Destination) and an AddMapDirections WebBlock. I also have a hidden button that gets clicked on page load. This translates coords from navigator.geolocation to an address for the origin and refreshes the Origin input and the AddMapDirections WebBlock.

However, whenever this page gets loaded, I get two errors - one is that an argument was empty and directions can't be loaded. The other is after the AJAX refresh happens - the AddMapDirections can't find the RouteMap, even though that never gets refreshed. In short, I don't know how to fix this and I was wondering if anyone could help me out. I've looked at the demo code extensively and can't seem to figure it out.

E: After adding the map to the AJAX Refresh, I still get the errors, but at least the route shows up. I'd still appreciate help in getting the errors removed. Thanks in advance! :) 

Kind regards,
Robrecht

 

 

Robrecht Colson wrote:
Hey folks, 
I have a WebScreen that has a RouteMap, three inputs (Duration, Origin, Destination) and an AddMapDirections WebBlock. I also have a hidden button that gets clicked on page load. This translates coords from navigator.geolocation to an address for the origin and refreshes the Origin input and the AddMapDirections WebBlock.

However, whenever this page gets loaded, I get two errors - one is that an argument was empty and directions can't be loaded. The other is after the AJAX refresh happens - the AddMapDirections can't find the RouteMap, even though that never gets refreshed. In short, I don't know how to fix this and I was wondering if anyone could help me out. I've looked at the demo code extensively and can't seem to figure it out.

E: After adding the map to the AJAX Refresh, I still get the errors, but at least the route shows up. I'd still appreciate help in getting the errors removed. Thanks in advance! :) 

Kind regards,
Robrecht

 

 
Hey there, Robert,

Let me start by saying I would use a regular map in that specific case: AddMapDirections will add a route to a map by itself, so I'm not sure why you need a Route Map. After translating the coordinates to an address and calling AddMapDirections, you should have a map with the route you want. If you don't want to show the map until you have the route ready, you can hide the Map inside an If and then switch its value and refresh it.

However, since I don't know the specific errors you have, it's hard for me to understand if this solution will solve everything. Can you please be a bit more specific on both errors? Maybe provide me with an URL I can look at?

Best regards,

Carlos Simões
Thanks for the help, Carlos. I replaced the RouteMap with a regular map, and I got the routes to show up, but I'm still getting the errors. You can check them out here. The application doesn't save your coordinates so you don't need to worry about privacy issues :) 

Kind regards,
Robrecht 
Robrecht Colson wrote:
Thanks for the help, Carlos. I replaced the RouteMap with a regular map, and I got the routes to show up, but I'm still getting the errors. You can check them out here. The application doesn't save your coordinates so you don't need to worry about privacy issues :) 

Kind regards,
Robrecht 
Ok, Robrecht (sorry for the typo back there :P),

Looking at your page's DOM, I can see you are using a AddDirections block, along with 'navigator.geolocation'. Last time I checked, this JS variable took some time to return a valid value, which might not be ready the first time the page (including the AddDirections block) is rendered.

Can you try adding directions through the appropriate AddDirections action instead? A good spot to place it would be at the end of the flow of the hidden button's click handler.

If this doesn't cut it, could you please send me the eSpace so I can have a look? One with just the problematic screen would do, if you're concerned with the recipe of your secret sauce ;).

Hope it helps!

Carlos Simões
Haha, no worries - my name is Robert, only in Dutch ;). 
Using the action instead of the web block worked - placing it at the end of the hidden button's click handler worked perfectly. Many thanks for the help! 

Kind regards,
Robrecht