Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I work with google map in that my task is show the area using draw dynamic polygon on map.
This polygon should be draw by given area and city name.

i want output like this map http://www.justdial.com/Vadodara/Four-Wheelz-%3Cnear%3E-Old-Padra-Road/0265PX265-X265-130706174318-V6N1_VmFkb2RhcmEgQ2FyIERlYWxlcnM=_BZDET/map[^]

and for that i try this on but it not work for me so please give me some good code or refernce for doing this task.
Posted
Updated 30-Jul-13 20:35pm
v2

1 solution

you can use this code just pass the location in query string

HTML
<html>
<head>
    <script>
        function getQueryStrings() {
            var assoc = {};
            var decode = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); };
            var queryString = location.search.substring(1);
            var keyValues = queryString.split('&');

            for (var i in keyValues) {
                var key = keyValues[i].split('=');
                if (key.length > 1) {
                    assoc[decode(key[0])] = decode(key[1]);
                }
            }

            return assoc;
        }

        var qs = getQueryStrings();
        var myParam = qs["address"];
           var lat = '';
            var lng = '';
             var marker='';
        var geocoder;
        var map;
        function codeAddress() {
            geocoder = new google.maps.Geocoder();
          
            var address = myParam;
            geocoder.geocode({ 'address': address }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    lat = results[0].geometry.location.lat(); //getting the lat
                    lng = results[0].geometry.location.lng(); //getting the lng
                    map.setCenter(results[0].geometry.location);
                    //add the pin point
                     marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location,
                        animation: google.maps.Animation.DROP,
                        
                    });
                        
                     //add circle in map
                  var draw_circle = null;  // object of google maps polygon for redrawing the circle
                    rad = 800; // convert to meters if in miles
                    if (draw_circle != null) {
                        draw_circle.setMap(null);
                    }
                    draw_circle = new google.maps.Circle({
                        center: map.getCenter(),
                        radius: rad,
                        strokeColor: "#FF0000",
                        strokeOpacity: 0.8,
                        strokeWeight: 2,
                        fillColor: "#FF0000",
                        fillOpacity: 0.10,
                        map: map
                    });
                 //End of  circle in map
      


                    //add the popup on pin point.
                    var infowindow = new google.maps.InfoWindow({
                        content: "<h3 style="font-family:sans-serif;">"+address+"</h3>"
                    });
                    makeInfoWindowEvent(map, infowindow, marker);
                    markers.push(marker);

                    function makeInfoWindowEvent(map, infowindow, marker) {
                        google.maps.event.addListener(marker, 'click', function () {
                            infowindow.open(map, marker);
                        });
                    }
                    google.maps.event.addDomListener(window, 'load', initialize);
                    //End of add the popup on pin point.
                }
                else {
                    alert("Geocode was not successful for the following reason: " + status);
                }
            });


            //plot the map
            var latlng = new google.maps.LatLng(lat, lng);
            var myOptions = {
                zoom: 15,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }
                         map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
          
   
           }

        window.onload = function () {
            codeAddress();
        }
    </script>
    <style type="text/css">
        body
        {
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
    <script src="http://maps.google.com/maps/api/js?libraries=places®ion=uk&language=en&sensor=true"></script>

    <div id="map_canvas" style="height: 100%; width: 100%; margin: 0em;">
    </div>
</body>
</html>
 
Share this answer
 
Comments
Member 10955199 18-Jul-14 4:45am    
Can you please let me know what is the string format ??
i tried this code but its not working for me
please help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900