Address in PHP variable, Google Maps embedding without Javascript?

I consider myself to be an average PHP coder, but I can barely edit the few bits of JavaScript code that I need on my websites. I have an address in a PHP variable and I would like a simple map to show up on my webpage with that address. I've done some research on the internet and I find a lot op geocoding, converting an address to a location the Google API understands, but I'm completely lost. Is there no simple piece of code to in which I can embed my variables?

Answers


You can use an iframe and pass the address as an URL parameter.

<iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?q=<?php echo $yourAddress; ?>&output=embed"></iframe>

You'll have to use the Geocoder API.

Here you go ( original can be found here ) :

<head>
...
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
  var geocoder;
  var map;
  function initialize() {
    geocoder = new google.maps.Geocoder();

    var mapOptions = {
      zoom: 12, //Change the Zoom level to suit your needs
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    //map_canvas is just a <div> on the page with the id="map_canvas"
    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

    //Your Variable Containing The Address
    var address = "<?php echo $AddressVariable; ?>"; 
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        //places a marker on every location
        var marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        });
      } else {
        alert('Geocode was not successful for the following reason: ' + status);
      }
    });

  }

</script>
...
</head>

Add this to the opening body tag of your page to initialize the map:

<body onload="initialize()">

And here's the documentation for the Geocoder class.


These links are use full to you..not the exact link but its use full :) tc..

1)remove-address-bubble-from-google-maps-iframe

2) google maps


<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<?php 
 $address = str_replace(" ", "+",$address_variable);
?>
<iframe style="width:100%;height:50%;" frameborder="0" id="cusmap" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?q=<?php echo $address; ?>&output=embed"></iframe>

Need Your Help

How to create multiple levels of indentation in Javadoc?

documentation javadoc indentation nested-lists

Suppose, that as part of documenting your code (Javadoc) you want to indicate that the relationships between elements using deep indentation.

How do I check OS with a preprocessor directive?

c operating-system c-preprocessor conditional-compilation

I need my code to do different things based on the operating system on which it gets compiled. I'm looking for something like this: