Brainsofsteel header

How to embed a google map with marker in PHP

Subject: Programming

Description: How to easily embed a Google map with a marker


submit to reddit Posted by David Caldwell on 26/08/13 at 12:13

Sometimes something that sounds complicated turns out to be easy.  I was creating a page that would display details of councils taken from an xml page, I wanted to embed a google map zoomed in on the latitude or longitude and showing a map marker.

The PHP Bit

Declare two variables one for latitude and One for longitude, in this case I'm getting them from an xml file, but you could easily get them from a database

<?

$lat = $council->lat;
$lng = $council->lng;

?>

The Google Map Bit

We are using a static map, for simplicity I am avoiding the javascript or iframe routes.  I have set the map type to hybrid. 

<img src="http://maps.google.com/maps/api/staticmap?center=<?php echo $lat ?>,<?php echo $lng ?>&zoom=14&markers=<?php echo $lat ?>,<?php echo $lng ?>&maptype=hybrid&&size=400x300&sensor=false" style="width: 400px; height: 400px;" />

 

 

 

Keywords: php, google map, marker, embed




comments powered by Disqus

 Subscribe in a reader

RSS Feed

Latest Posts

17/11/15
How to Create a Time Sheet in Excel
15/11/15
Handling time and dates in PHP
03/02/15
How to Enhance Photographs with the Gimp
25/01/15
How to Cook Pigeon
25/01/15
Telling the Time
24/01/15
An Old Travel Card
10/09/14
How to Learn the Nine Times Table
09/08/14
How to Calculate the Direction between two Points
01/08/14
Making a large Google XML sitemap
18/05/14
How to make a pyramid