Good Morning,
I have latitude and longitude data in my form array:
I want to display a marker on the google map api at the above coordinates
How can I insert the latitude/longitude data into the javascript code?
I have latitude and longitude data in my form array:
[latitude] => 56.298253152913865
[longitude] => -4.998779296875
I want to display a marker on the google map api at the above coordinates
function myMap() {
var myLatLng = {lat: ?????????????, lng: ????????????????};
var map = new google.maps.Map(document.getElementById('map'), {
center: myLatLng,
zoom: 18,
mapTypeId: google.maps.MapTypeId.HYBRID,
disableDefaultUI: true
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Your chosen location'
});
}
How can I insert the latitude/longitude data into the javascript code?
Hi szabob,
I'm not clear where in the form flow you are doing this. Are you adding the marker in the browser as soon as a place is selected, or is this code running in the On Submit event after the form is submitted?
Bob
I'm not clear where in the form flow you are doing this. Are you adding the marker in the browser as soon as a place is selected, or is this code running in the On Submit event after the form is submitted?
Bob
Hi Bob,
This is a multi-page form with 2 pages. The first page gets the coordinates and after submitting the form the second page will show the map with a marker. My debug on the 2nd page looks like this:
Regards
Bob
This is a multi-page form with 2 pages. The first page gets the coordinates and after submitting the form the second page will show the map with a marker. My debug on the 2nd page looks like this:
[map-search] =>
[chronoform] => map-search
[event] => page2
[latitude] => 57.00485033534416
[longitude] => -3.614501953125
Regards
Bob
Hi szabob,
You can add this to the Load JavaScript action for the second page
Then in the function you can use
Bob
You can add this to the Load JavaScript action for the second page
var lat, lng;
lat = <?php echo $form->data['map-search']['latitude']; ?>;
lng = <?php echo $form->data['map-search']['longitude']; ?>;
Then in the function you can use
function myMap() {
var myLatLng = {lat: lat, lng: lng};
. . .
I think that should work OK.
Bob
This topic is locked and no more replies can be posted.