0

I am trying to add markers to a google map but need to bring lat/lng values in from php/mysql. The code I have below is not working, just wondering if I am going about this the right way! Thanks!

function addMarker(lat, lng){

        var point = new google.maps.LatLng(lat, lng);
        var marker = new google.maps.Marker({
            position: point,
            map: map
        });

    }
    function initialize() {
        var mapOptions = {
            center: {lat: 54.872128, lng: -6.284874},
            zoom: 15
        };

        map = new google.maps.Map(document.getElementById('map-canvas'),
                mapOptions);

                 <?php
                $query = mysql_query("select * from tester");
                while($row = mysql_fetch_array($query)){
                    $lat = $row['lat'];
                    $lng = $row['lng'];
                    echo ("addMarker($lat, $lng);");
                }
                ?>

    }
fst104
  • 816
  • 1
  • 10
  • 22
  • 1
    *"below is not working"* - can you define "not working"? Oh.. and you're mixing APIs, can't do that. Make sure that file's `.php` too and not `.js` – Funk Forty Niner Aug 07 '15 at 13:44
  • 1
    You're mixing `mysql_*` and `mysqli_*` functions. That won't work. – Jay Blanchard Aug 07 '15 at 13:44
  • Sorry that was a typo. Yeah, the map just doesn't appear for me at all... if i remove the php part in initialize() it shows up ok but I get SyntaxError: expected expression, got '<' when I have the php inserted! – fst104 Aug 07 '15 at 13:51
  • Isn't possible to use php and javascript with it (php vars != js vars), you have to parse your query. Enocode array to json format with php, and use JSON API in javascript to get response. – Célestin Aug 07 '15 at 14:31

0 Answers0