Solved

javascript

Posted on 2011-09-02
5
335 Views
Last Modified: 2012-05-12
Hey guys i need help to convert this javascript to c# code please, it is a google map that use xml

 
<script language="javascript" type="text/javascript">

    // Google Map API Javascript

    var map;
    var geocoder;
    var http_request = false;
    var lat = 0;
    var lng = 0;
    var startingLat = -25.65143;  // view of Pretoria
    var startingLng = 28.256836;  // view of Pretoria
    var startingZoom = 9;
    var maximumZoom = 15;

    function mapLoad() 
    {
        if (GBrowserIsCompatible()) {
            geocoder = new GClientGeocoder();
            map = new GMap2(document.getElementById('map'));
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            map.enableScrollWheelZoom();
            map.setCenter(new GLatLng(startingLat, startingLng), startingZoom);
        }
    }

    function searchLocations() 
    {
        var ddArea = document.getElementById("<%=ddArea.ClientID%>"); 
        var area = ddArea.options[ddArea.selectedIndex].value;
        var searchString = area  + ', Pretoria, Gauteng';

        geocoder.getLatLng(searchString, function(latlng) 
        {
            if (!latlng) 
            {
                alert(searchString + ' - not found');
            } 
            else 
            {
                searchLocationsNear(latlng);
            }
        });
    }

    function searchLocationsNear(center) 
    {
        var ddArea = document.getElementById("<%=ddArea.ClientID%>"); 
        var area = ddArea.options[ddArea.selectedIndex].value;
        var searchUrl = 'SearchResponse.aspx?lat=' + center.lat() + '&lng=' + center.lng() + '&area=' + area;
        GDownloadUrl(searchUrl, function(data) 
        {
            var xml = GXml.parse(data);
            var sidebar = document.getElementById('sidebar');
            sidebar.innerHTML = '';
            map.clearOverlays();

            if (xml.documentElement == null) 
            {
                sidebar.innerHTML = 'No results found.  Please try widening your search area.';
                map.setCenter(new GLatLng(startingLat, startingLng), startingZoom);
                return;
            }

            var markers = xml.documentElement.getElementsByTagName('marker');

            if (markers.length == 0) 
            {
                sidebar.innerHTML = 'No results found.  Please try widening your search area.';
                map.setCenter(new GLatLng(startingLat, startingLng), startingZoom);
                return;
            }

            var bounds = new GLatLngBounds();
            for (var i = 0; i < markers.length; i++) 
            {
                var address = markers[i].getAttribute('address');
                var area = markers[i].getAttribute('area');
                var location = markers[i].getAttribute('location');
                var p_code = markers[i].getAttribute('p_code');
                var point = new GLatLng(parseFloat(markers[i].getAttribute('Latitude')), parseFloat(markers[i].getAttribute('Longitude')));

                var marker = createMarker(point, address, area, location, p_code);

                map.addOverlay(marker);
                var sidebarEntry = createSidebarEntry(marker, address, area, location);
                sidebar.appendChild(sidebarEntry);
                bounds.extend(point);
            }

            var pointCenter = bounds.getCenter();
            var iZoomLevel = map.getBoundsZoomLevel(bounds);
            if (iZoomLevel > maximumZoom) { iZoomLevel = maximumZoom; }
            map.setCenter(pointCenter, iZoomLevel);

        });
    }

    function createMarker(point, address, area, location, p_code) 
    {
        var marker = new GMarker(point);
        var html;
        if (location == null) 
        {
            html = '<br/>' + address + '<br/>' + area + '<br/>' + p_code;
        }
        else 
        {
            html = '<br/>' + address + '<br/>' + area + '<br/>' + location + '<br/>' + p_code;
        }
        GEvent.addListener(marker, 'click', function() 
        {
            marker.openInfoWindowHtml(html);
        });
        return marker;
    }

    function createSidebarEntry(marker, address, area, location) 
    {
        var div = document.createElement('div');
        var address;
        if (location == '' || location == null) 
        {
            address = address + '<br/>' + area;
        }
        else 
        {
            address = address + '<br/>' + area + '<br/>' + location;
        }
        var html =  address;
        div.innerHTML = html;
        div.style.cursor = 'pointer';
        div.style.marginBottom = '5px';
        GEvent.addDomListener(div, 'click', function() 
        {
            GEvent.trigger(marker, 'click');
        });
        GEvent.addDomListener(div, 'mouseover', function() 
        {
            div.style.backgroundColor = '#eee';
        });
        GEvent.addDomListener(div, 'mouseout', function() 
        {
            div.style.backgroundColor = '#fff';
        });
        return div;
    }

    </script>

Open in new window

0
Comment
Question by:JCWEBHOST
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:mohammad827
ID: 36472332
Well unless you have GoogleMap API for .Net you can't do it
0
 
LVL 4

Accepted Solution

by:
mohammad827 earned 500 total points
ID: 36472365
Well check this out. Seems to be what you want http://www.codeguru.com/csharp/.net/net_asp/controls/article.php/c10539/
0
 
LVL 19

Expert Comment

by:Bardobrave
ID: 36472470
Why do you need to translate it?

You've set the question on ASP.NET section, so I supose you are building a web app. If you are using a web app the usua way to build and call google maps is through client code.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 36472680
And, honestly, "convert this code for me" is not a question - it is a command.
0
 

Author Closing Comment

by:JCWEBHOST
ID: 36482774
thanks
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ado.net AddWithValue when using IN condition 7 45
Getting robots.txt Error 9 57
Data Analysis 7 59
Ajax calendar distorted 4 19
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question