Forum Academy Marketplace Showcase Pricing Features

Trying to insert dynamic data into an latlgn html statement

Hi all,
I am trying to display a google map that has a starting and ending point. If I hard code the coordinates like I’ve illustrated below I get the map I want.

//** Enable below for Traffic layer

//var trafficLayer = new google.maps.TrafficLayer();

//trafficLayer.setMap(map);

directionsDisplay.setMap(map);

directionsService.route({

origin: new google.maps.LatLng(40.7986638, -73.9657349),

destination: new google.maps.LatLng(40.7980343, -73.970139),

travelMode: google.maps.TravelMode.DRIVING

},

If, on the other hand, I try to insert dynamic data (as a numeric field) in place of the hard coded numbers I get an HTML syntax error. the code looks like this.

//** Enable below for Traffic layer

//var trafficLayer = new google.maps.TrafficLayer();

//trafficLayer.setMap(map);

directionsDisplay.setMap(map);

directionsService.route({

origin: new google.maps.LatLng(Search for LatLng’s Seeker Lat, Search for LatLng’s Seeker Lng),

destination: new google.maps.LatLng(Search for LatLng’s Spot Lat, Search for LatLng’s Spot Lng),

travelMode: google.maps.TravelMode.DRIVING

},

Is there a way to move a variable into this html statement so that the map reflects the users input?
Thanks
Chris


Please pick a subcategory to help organize the information. Thanks!

Also, the more context you provide with your questions (screenshots, link to an open app, etc.), the more likely you’ll get good help quickly :slight_smile:

I’ve got no answer for you, but I might be of some help troubleshooting.

Where are you inserting this code? You’re saying an html statement, but this code is not html? Where is the error printed?

Edit: Is your goal to print the user’s dynamic input into the google map api’s LatLng field, and then run the query? Sorry if I’m not being helpful, I’m just also interested in directions

Yes, just put the cursor where you want the variables and choose Insert Dynamic … When it comes up. You will want to overwrite the hard coded lat long.

Thank you NigelG and Skylershelton, I was preparing to send better examples using the Forumapp3 app but when I set up the two pages to demonstrate my problem I no longer had the problem. I must have done something strange in my application. I have to go back and check. Anyway I set up the first map page with the Lat and Lng values hardcoded inside the HTML. I got a map. Then I set up a table and stored the same Lat and Lng values and then called the table from the html. To my surprise the map still works.
You can both maps at https://forumapp3.bubbleapps.io/version-test/cwb_map1?debug_mode=true. Thank you both for your help. I will clean my work out of Forumapp3 in several days so that it does not get unnecessarily unruly.
Chris

1 Like