Google map markers within give radius e.g. 30 miles from SQL server table using classic asp

Hi All,

I'd like to take a dynamically created dataset from a MSSQL database table using classic asp and plot them on a "google maps" map - ideally within a given range of say 30 miles.

For exmaple, I have a MSSQL tables called LocalStores, that have the following data fields;

1. Store Name
2. Store Type
3. Store Latitude
4. Store Longitude

I've signed up for my Google Key, but cannot work out to extract my MSSQL data using Classic ASP and to plot markers onto a Google maps - I also want to customise the markers based on store type.

I'm totally confused with all the options - I also need the maps to work on Windows/Android and Apple devices - with my example code below does not seem to, it only displays on Windows and not iPads etc.

Any help would be greatly and very much appreciated.

Regards

JamWales

My Code  so far;

========================


default.asp

<%@  language="VBScript" %>
<%Option Explicit%>
<!--#include file="Controls/GoogleMaps.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Google Maps Searcher</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <%
        ' Initialize Google Maps object, which encapsulates all functionality
        Dim googleMaps : Set googleMaps = New ASP2_Controls_GoogleMapsSearcher
'        googleMaps.APIKey = "xxxxx"
             googleMaps.APIKey = xxxxx"
    %>
</head>
<body>
    <%
        ' Render UI
        googleMaps.Render      
            
            Response.Write "<br><br>Map Drawn - can you see it?<br><br>"

        ' Dispose
       
    %>
</body>
</html>

========================
GoogleMaps.asp

<%
Class ASP2_Controls_GoogleMapsSearcher

    ' ///// Member variables//////

    Dim m_apiKey ' As String
    Dim m_ID ' As String
    Dim m_customFieldLabel ' As String
    Dim m_customAttendees ' As String
    Dim m_attributes ' As String

    ' ///// Properties variables//////

    Public Property Get APIKey
        APIKey = m_apiKey
    End Property

    Public Property Let APIKey(value)
        m_apiKey = value
    End Property

    ' ///// Construciton variables//////

    ' Constructor
    Private Sub Class_Initialize
    End Sub

    ' Destructor
    Private Sub Class_Terminate
    End Sub

    ' ///// Public Methods variables//////

    ' Renders the control UI
    Public Sub Render()
%>
<div id="mapsearcher" style="left: 10px; position: relative;">
    <form id="frmsearcher" method="post" action="">
    Area or Zip Code:
    <input type="text" size="30" name="address" id="address" class="required email">&nbsp;&nbsp;
    Radius:
    <input type="text" size="4" name="radius" value='30' id="radius">&nbsp;
    <input id="optMiles" name="group0" type="radio" title="Miles" checked="checked" />Miles&nbsp;
    <input id="optKm" name="group0" type="radio" title="Kilometers" />Km<br />
    <span id="errMsg" style="font-style: oblique; color: Red"></span>
    <input type="button" value="Geocode" onclick="codeAddress();">
    </form>
</div>
<div id="map" style="width: 1000px; height: 600px; top: 10px; left: 10px; position: relative;
    visibility: hidden;">
</div>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=<%=Me.APIKey %>&sensor=false"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script type="text/javascript">
    var geocoder;
    var map;
    var cCircle;
    var addr = "";
    var rad = "";

    $(document).ready(function () {
        $("#address").keydown(clearErr);
    });

    function mapLoader() {
        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(-34.397, 150.644);
        var myOptions = {
            zoom: 9,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        map = new google.maps.Map(document.getElementById("map"), myOptions);
    }

    function codeAddress() {
        addr = $("#address").val();
        rad = $("#radius").val();

        if (map == null) {
            mapLoader();
        }

        if (validate()) {
            geocoder.geocode({ 'address': addr }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    map.setZoom(9);
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location,
                        title: addr
                    });
                    makeRadius();
                    $("#map").css("visibility", "visible");
                } else {
                    $("#errMsg").html("Geocode was not successful for the following reason: " + status + "<br />");
                }
            });
        }
    }

    function makeRadius() {

        if (cCircle != null) {
            cCircle.setMap(null);
        }

        if ($('#optMiles').attr('checked') == 'checked') {
            try {
                var rVal;
                rVal = Math.round(1.61 * rad);
                rad = rVal * 1000;
            }
            catch (e) {
                $("#errMsg").html(e.Message + "<br />");
            }
        }
        else {
            rad = rad * 1000;
        }

        var populationOptions = {
            strokeColor: "#FF0000",
            strokeOpacity: 0.8,
            strokeWeight: 2,
            fillColor: "#FF0000",
            fillOpacity: 0.35,
            map: map,
            center: map.center,
            radius: rad
        };
        cCircle = new google.maps.Circle(populationOptions);
    }

    function validate() {

        var regLet = /\d+|\w+/i;
        var regRad = /^(\d+)+$/i;

        if (!regLet.test(addr)) {
            $("#errMsg").html("*Plase type correct Area or Zip code<br />");
            return false;
        }

        if (rad == "") {
            rad = "30";
            return true;
        }

        if (!regRad.test(rad)) {
            $("#errMsg").html("*Plase type correct Radius value<br />");
            return false;
        }

        return true;
    }

    function clearErr() {
        $("#errMsg").html("");
    }

</script>
<%
   End Sub
End Class
%>


========================
JamieAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
replace :
    $(document).ready(function () {
        $("#address").keydown(clearErr);
    });

Open in new window

by :
    $(document).ready(function () {
    mapLoader();
        $("#address").keydown(clearErr);
    });

Open in new window

0
JamieAuthor Commented:
Hi leakim971,

Many thanks for your reply - the maps are displaying on iPhones etc now - thank you very much - rocking!

Do you know how I would place multiple markers from my SQL database onto the map - I can write the classic asp sql calls, just cannot work out how to feed them into the Google map?

Regards

JamWales
0
leakim971PluritechnicianCommented:
Hi JamWales,

Check this thread, hope it will help you :
http://www.experts-exchange.com/Programming/Languages/.NET/Q_27226736.html?cid=1133#a36272263

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JamieAuthor Commented:
Hi leakim971 - thank you for all your help, much appreciated. Regards JamWales
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.