Google Mpas

Hello, im trying to add a google map and get the latitude and longitude.
I first try using a blank application. with the following code:

(copy paste in a blank app…)

$latitude= -27.450809;
$longitude= -58.986476;

$_head = "
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name=‘viewport’ content=‘initial-scale=1.0, user-scalable=no’>
<meta charset=‘utf-8’>
<style>
html, body, #map-canvas {
margin: 0;
padding: 0;
height: 90%;
}
</style>

&lt;script src='https://maps.googleapis.com/maps/api/js?key=AIzaSyDYaJNMFEWfDO0I3c0rpW1Qo1vRN1Ur8eU'&gt;&lt;/script&gt;
&lt;script&gt;

var map;
function initialize()
{
var myLatlng = new google.maps.LatLng(".$latitude.",".$longitude.");
var mapOptions = {
zoom: 16,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

    map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
     
    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'Dependencia',
        draggable:true
        });

 marker.addListener('drag',function(event) {
    
    document.getElementById("latitud").value = event.latLng.lat();
    document.getElementById("longitud").value = event.latLng.lng();
});

marker.addListener('dragend',function(event) {
    document.getElementById("latitud").value = event.latLng.lat();
    document.getElementById("long").value = event.latLng.lng();
});

}

google.maps.event.addDomListener(window, ‘load’, initialize);
</script>
</head>
<body>
<div id=‘map-canvas’></div>

</body>
</html>
";

$escrever = ($_head);
echo $escrever;


the problem is:
im using a form to complete other data and i have to call the blank app to get the latitude and longitude… how can i do it?
how can i get the values an put it on my lat and long fields of the form??

thanks

Write on initial value of your fields Lang and lat of your form, values [glolong] and [glolang] for example. When you redirect to the form, pass in URL this values, somehnt like…
…yourproject/yurform/?glolong=somevalue&glolat=somevalue

Sorry for misspelled words. I’m on mobile and cant edit, but you got the point

Thank you Giu, I?ve got it. !

OK, so how you add Google API globally ?
I trying something similar but I get error:

Parse error: syntax error, unexpected 'latitud' (T_STRING) in C:\Program Files (x86)\NetMake\v81\wwwroot\scriptcase\app\TECREP\Distance\index.php on line 1156

it seems that the App is not linked to the google API, although I see the correct line here:

<script src='https://maps.googleapis.com/maps/api/js?key=AIzaSyDYaJNMFEWfDO0I3c0rpW1Qo1vRN1Ur8eU'></script>

Arthur

Arthur

Not sure if this helps but why don’t you load up src and long/lat as a global variable’s in the OnLoad

example:
[src]=‘https://maps.googleapis.com/maps/api/js?key=AIzaSyDYaJNMFEWfDO0I3c0rpW1Qo1vRN1Ur8eU’;
[latitude]= -27.450809;
[longitude]= -58.986476;

Then in the application -> Global Variable check off Session and Out