Skip to main content

Different map for a different browser!

            The title simply implies that detect the client's browser and then display the map accordingly! This is basically important when you are developing a map application for mobiles. Mobiles usually have a small screen and the maps that look brilliant on the desktops don't look the same on the mobile screens!

            Well, in my example, I am considering only two of the most popular browsers in use - Mozilla and IE. The application detects whether the client's browser is one of the two and then renders the map accordingly! If you are viewing the example in Mozilla, then you will see a 600 X 800px map, whereas if you are viewing it in IE, you will see a smaller 500 X 500px map! Here is the code...

<html>
<title>Basic Google Map Example - Detect browser and render map accordingly
</title>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
var map;
function load()
{
    var useragent = navigator.userAgent;
    map = new google.maps.Map(document.getElementById("map_area"),
    {
        zoom: 6,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: new google.maps.LatLng(21.698265,79.035645)
    });
    if (useragent.indexOf('MSIE') != -1)
    {
        map_area.style.height = '500px';
        map_area.style.width = '500px';
    }
    else if (useragent.indexOf('Mozilla') != -1)
    {
        map_area.style.height = '600px';
        map_area.style.width = '800px';
    }
}
</script>
</head>
<body onload="load()">
<div id="map_area">
</div>
</body>
</html>

             The key focus point in this code is "navigator.userAgent". This detects the type, version, etc. of the current browser being used! The output of the above code will appear as seen in the images below!

Output - Browser used IE

 Output - Browser used Mozilla

            Please try on other browsers as well. Please leave a comment about the results you observe. Hope you like the post. Please leave your feedback here!

Comments

Recommended for You

Playing with the markers and info window bubbles...

    In the last few posts, we have seen some marker examples and some information window examples. Now, lets do something interesting combining these two things. Just writing that "This is an info window" in the information bubble is not very interesting! And I know this...Have gone through the same phase!     So, today we will do something interesting! We will display the latitude- longitude co-ordinates of the point that the user clicks on the map! Doing this is not at all complex! Copy paste the following code and you will see for yourself a map coming to life!     The output of the above code looks as seen in the result section above! If you have any queries regarding the above code please comment on the blog post or feel free to contact me at my mail ID .

Where does Google get it's live traffic data from?

Referring to a post that I wrote earlier, Google’s - Live traffic Layer , ever wondered how Google collected this data? I was wondering the other day, how Google received live data to display it on their maps as a layer! I looked up the web and found something very interesting and am sharing the same with you all. As we all know, the traffic layer is available most accurately in several states in USA. Most major metro areas in the US have sensors embedded in their highways. These sensors track real time traffic data. Easy to miss at high speeds (hopefully anyway, traffic permitting), more commonly noticed may be the similar sensors that often exist at many busy intersections that help the traffic lights most efficiently let the most amount of people through. The information from these tracking sensors is reported back to the Department of Transportation (DOT). The DOT uses this data to update some of the digital signs that report traffic conditions in many metro areas. They als

Panoramio Layer...

    Let's start with the obvious question first...What is Panoramio? Panoramio is a geolocation-oriented photo sharing website. Panoramio website was officially launched on October 3, 2005 by Joaquín Cuenca Abela and Eduardo Manchón Aguilar, two Spanish entrepreneurs and was acquired by Google in July 2007.     Accepted photos uploaded to the site can be accessed as a layer in Google Maps, with new photos being added at the end of every month. The site's goal is to allow Google Maps and Google Earth users to learn more about a given area by viewing the photos that other users have taken at that place. The website is available in several languages and can be viewed here .     You may add photos from Panoramio as a layer to your maps using the PanoramioLayer object. The PanoramioLayer renders a layer of geotagged photo icons from Panoramio on the map as a series of large and small photo icons. Let us now have a look at the following code to understand the concept in more det

Map Loading...

    The blank web page seems so boring and dull when the map is still loading. You will come across such a situation quite often where you will be having a slow internet connection! We cannot do anything about the slow internet connection, but we can surely avoid the dull blank web-page by using a simple trick. We can place a "loading" image at the center of the web page so that the page doesn't look blank! An image like this:             The following code will show you how this can be done and here it is!     As you all can see the code is very very simple and the output will look as seen in the results section above. The image below shows the loading stage of the map.       Do let me know what you think about the examples shared here! Do leave your comments here! Till the next example, happy mapping!

GIS Technology to identify all properties in BBMP Limits

          The Bruhat Bangalore Mahanagara Palike (BBMP) has for the last two years, been in the process of conducting a massive exercise to map the 13.87 lakh properties in the 198 wards in the city. Geographical Information System (GIS) has proven to be an effective tool for analysing and displaying thematic maps of all the roads for proper evaluation and correction of zones.            As of now, 11 lakh properties have come under the tax net. The aim of this programme, which is perhaps the first such exercise being conducted in the country on such a large scale, covering 800 square km, is to bring all properties under the tax net and ensure that the BBMP has accurate information pertaining to the properties’ dimension, built-up area, land use and classification. The process of validation of GIS maps will be completed in January 2011.           The process uses satellite digital maps of the BBMP area to generate a vector map from the information obtained. These high r