2016-05-07 5 views
-1

Ich suche derzeit nach einer Möglichkeit, eine Google Maps-Karte auf meiner Seite anzuzeigen. Bis jetzt kann ich die Karte zeigen, aber ich möchte, dass die Koordinaten Variablen sind.Anzeigen von Google Maps mit Koordinaten als Variablen

My PHP variables are $lat and $lng 

Dies ist mein Code so weit

<script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script><div style='overflow:hidden;height:440px;width:700px;'><div id='gmap_canvas' style='height:440px;width:700px;'></div><style>#gmap_canvas img{max-width:none!important;background:none!important}</style></div><script type='text/javascript'>function init_map(){var myOptions = {zoom:15,center:new google.maps.LatLng(<VARIABLE>,<VARIABLE>),mapTypeId: google.maps.MapTypeId.ROADMAP};map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions);marker = new google.maps.Marker({map: map,position: new google.maps.LatLng(<VARIABLE>,<VARIABLE>)});infowindow = new google.maps.InfoWindow({content:'<strong>Title</strong><br>London, United Kingdom<br>'});google.maps.event.addListener(marker, 'click', function(){infowindow.open(map,marker);});infowindow.open(map,marker);}google.maps.event.addDomListener(window, 'load', init_map);</script> 

Vielen Dank im Voraus

Antwort

2

JS Objekt erstellen

var displayOnMap = {"lat":<?php echo $lat; ?>, "lng":<?php echo $lng; ?>}; 

es dann wie

passieren
new google.maps.LatLng(displayOnMap.lat, displayOnMap.lng); 
Verwandte Themen