user1189269
user1189269

Reputation: 25

Conversion of a String to a latitude and longitude using google maps in PHP

I have this code that should show me Marker in Google map:

var latitudine='<?echo php $_POST['lat']; ?>';
    var longitudine='<?echo php $_POST['lon']; ?>';
    var myCenter=new google.maps.LatLng(latitudine,longitudine);
   function initialize()
   {
    var mapProp = {
    center: myCenter,
    zoom:5,
    mapTypeId: google.maps.MapTypeId.ROADMAP
   };

 var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);

  var marker = new google.maps.Marker({
  position: myCenter,
  title:'Click to zoom'
  });

 marker.setMap(map);

 // Zoom to 9 when clicking on marker
  google.maps.event.addListener(marker,'click',function() {
  map.setZoom(15);
  map.setCenter(marker.getPosition());
  });
}
google.maps.event.addDomListener(window, 'load', initialize);
    </script>

But when I visualize the map, i haven't the marker. In which way can i transfer the values "Latitudine" and "Longitudine"?

Upvotes: 0

Views: 336

Answers (1)

strikernl
strikernl

Reputation: 55

EDIT: Threw out my entire previous answer. Looks like you did the echo syntax wrong:

var latitudine='<?echo php $_POST['lat']; ?>';
var longitudine='<?echo php $_POST['lon']; ?>';

should be

var latitudine='<?php echo $_POST['lat']; ?>';
var longitudine='<?php echo $_POST['lon']; ?>';

Upvotes: 1

Related Questions