Tuesday 23 October 2012

Bing Map using JavaScript


<script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3&mkt=en-us">
</script>

<script type="text/javascript">
        var map = null;
        var pinPoint = null;
        var pinPixel = null;

        $(document).ready(function () {
            jQuery.support.cors = true;
            $("#btnGetInfo").click(function () {
                $.ajax({
                    type: 'POST',
                    cache: false,
                    url: 'http://maps.google.com/maps/geo?q=ahmedabad&output=csv',
                    contentType: 'application/json; charset=utf-8',
                    success: onSuccess,
                    error: onError
                });

                function onSuccess(e) {

                    if (e != "") {
                        var LL = new VELatLong(e.split(',')[2], e.split(',')[3]);
                    }
                    else {
                        return false;
                    }
                    map = new VEMap('myMap');
                    map.LoadMap(LL, 15, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);
                    AddPin();
                }
                function onError(e) { alert(e.d); }
            });
        });

        
        function AddPin() {
            // Add a new pushpin to the center of the map.
            pinPoint = map.GetCenter();
            pinPixel = map.LatLongToPixel(pinPoint);
            map.AddPushpin(pinPoint);
        }
    </script>

<body onload="GetMap()">
    <form id="form1" runat="server">
    <div>
        <div id='myMap' style="position: relative; width: 1000px; height: 450px;">
        </div>
        <input id="btnGetInfo" type="button" value="Get Scene Information" name="getinfo">
        <br />
    </div>
    </form>
</body>

No comments:

Post a Comment