Showing posts with label Google Map. Show all posts
Showing posts with label Google Map. Show all posts

Saturday, December 29, 2012

how to show Google Static Map using javascript

We often use Google Static Map to show office location or shop location. Moreover, it is in wide use to display the direction from one place to another. This post will explain you the simple way how to use Javascript for displaying dynamic Google Map using Google Static Maps API V2.
Google Static Map using Javascript
First, it needs the following script in <head> tag.
<script type="text/javascript">
    var position = new Object();
    function showPosition(position) {
        var latlon = position.latitude + "," + position.longitude;
        var imgUrl = "http://maps.googleapis.com/maps/api/staticmap?center=" +
            latlon + "&zoom=16&size=500x400&sensor=false";
        document.getElementById("mapholder").innerHTML = "<img src='" + imgUrl + "' />";
    }
    window.onload = function () {
        position.latitude = 13.745674;
        position.longitude = 100.53422;
        showPosition(position);
    }
    function showMap() {
        position.latitude = document.getElementById("txtLat").value;
        position.longitude = document.getElementById("txtLon").value;
        showPosition(position);
    }
</script>
Secondly, create the image container and controls in <body> tag as below:
<form id="form1" runat="server">
    <div id="mapholder">
    </div>
    <div>
        <asp:Label ID="Label1" runat="server" Text="Latitude :"></asp:Label>
        <asp:TextBox ID="txtLat" runat="server" Text="13.715236" ClientIDMode="Static"></asp:TextBox><br />
        <asp:Label ID="Label2" runat="server" Text="Longitude:"></asp:Label>
        <asp:TextBox ID="txtLon" runat="server" Text="100.591233" ClientIDMode="AutoID"></asp:TextBox><br />
        <asp:Button ID="Button1" runat="server" Text="Show Map" onclientclick="showMap();return false;" />
    </div>
</form>
That's it. When it run, it shows one location and then press "Show Map" button to see another place.
This post is the last one for this year. See you next year. Thank.

Sunday, November 20, 2011

Google Static Maps API V2

The Google Static Maps API lets you embed a Google Maps image on your web page without requiring JavaScript or any dynamic page loading. The Google Static Map service creates your map based on URL parameters sent through a standard HTTP request and returns the map as an image you can display on your web page.

The following example contains the URL of a static map image of downtown New York City, which is displayed below:

http://maps.googleapis.com/maps/api/staticmap?center=Williamsburg,Brooklyn,NY&zoom=13&size=500x500&scale=1&format=jpg&maptype=roadmap&language=thai&markers=color:blue|label:S|11206&markers=icon:http://www.iblogseeker.com/favicon.ico|C11211&path=color:0x0000ff|weight:5|40.707255,-73.952193|40.708718,-73.95627|40.710475,-73.955197|40.720949,-73.956614&sensor=false

you can pass the parameters such as center, zoom, size, format, maptype, language, markers, path and sersor.

You can see details here:

http://code.google.com/apis/maps/documentation/staticmaps/index.html

How to find out latitudes and longitudes about your address.

Most people don't speak in latitudes and longitudes; they denote locations using addresses. The process of turning an address into a geographic point is known as geocoding and the Static Maps service can perform geocoding for you if you provide valid addresses. If you have doubt about how an address may geocode, you can test out the address using the follow Geocoding Utility.

http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html