Search code examples
htmlgoogle-mapsgoogle-maps-static-api

Google maps to show locations


In my application i want to show two or more points in the google maps and also need to draw a line between them. I want this to show by a tag of html. How can i do it??


Solution

  • So you need to use the static maps API.

    Here's an example with markers and a polyline:

    <img src="http://maps.googleapis.com/maps/api/staticmap?
    size=500x300
    &amp;sensor=false
    &amp;markers=color:green|label:1|51.511333,-0.119355
    &amp;markers=color:blue|label:2|51.507801,-0.107569
    &amp;markers=color:red|label:3|51.510999,-0.104297
    &amp;path=color:0xff0000ff|weight:5|51.511333,-0.119355|51.506205,-0.114462|51.507774,-0.10861|51.507801,-0.107569|51.5071,-0.107344|51.507207,-0.105016|51.507507,-0.104404|51.510999,-0.104297">
    

    enter image description here

    The last line starts off setting the attributes for the polyline, i.e. its color is red (ff0000). The last 'ff' indicates it's 100% solid, but you can vary these last two characters anywhere between 00 - FF (base 16) to go between 0 - 100% opacity (or if you leave those last two characters off entirely, it'll default to 50% opacity). It has a weight (thickness) of 5.
    After that, it's just a list of coordinates for the polyline, each one separated by a |

    Check the documentation: https://developers.google.com/maps/documentation/static-maps/intro#Paths