maps, php, sql. Enter coordinates into the database and reaver map (google) with these coordinates

Asked

Viewed 464 times

1

I have a dynamic map (at least I would like it to be), I wanted it to depend on the user, he entered the coordinates (based on a form) that he wanted and they were entered in the database... so far so good. But then how to enter these coordinates inside the formatting of google maps, in the parameter 'center'?

    <script type="text/javascript">

                google.maps.event.addDomListener(window, 'load', init);

                function init() {

                    var mapOptions = {
                        zoom: 14,
                        center: new google.maps.LatLng(LAT(COOR1), LONG(COORD2)),
                        mapTypeId: google.maps.MapTypeId.ROADMAP,
                        mapTypeControl: false,
                        streetViewControl: false,
                        scrollwheel: false,
                        panControl: false,
     };



    var mapElement = document.getElementById('map');


                var map = new google.maps.Map(mapElement, mapOptions);
            }
  • Ta, if I understand correctly, you are already saving the strings correctly, just need to center the map with them, that’s right ??

  • That’s it, I think I just solved the problem... The problem here was to insert coordinates stored in DB and retrieve them by php, they had to be inserted into javascript (in the 'center' parameter in the map). It was easy, I think I was just mental laziness. I’ll post the answer

1 answer

1


I got it this way:

<?php
$lat = '38.689527';
$long = '-9.351307';
echo '<script type="text/javascript">

    google.maps.event.addDomListener(window, "load", init);
    function init() {
        var mapOptions = {
            zoom: 14,
            center: new google.maps.LatLng(' .$lat. ', ' .$long. '),
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            mapTypeControl: false,
            streetViewControl: false,
            scrollwheel: false,
            panControl: false,
        };
        var mapElement = document.getElementById("map");
        var map = new google.maps.Map(mapElement, mapOptions);
    }

</script>';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.