1

I currently have markers for all of my subcontractors on a map. I have a variable for each row in the database containing the number of miles they are willing to travel.

How would I add the circles that cover that area?

<script>
    /*
     * MAP 2
     */
    jQuery(function() {
        "use strict";

        // init map
        var map = new GMaps({
            div: '#applicantLocation',
            lat: 39.8282,
            lng: -85.4373943,
            zoom: 4
        });

        <?php

            $sql = "SELECT * FROM vendorApps ORDER BY `dateReceived` DESC";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
            include "includes/php/getTimeAgo.php";
            // output data of each row
            while($row = $result->fetch_assoc()) {
                $zip    = $row["zip"];
                $getZip = "SELECT `lat` , `lng` FROM `zips` WHERE `zip` =  \"$zip\" ";
                $getZipResult = $conn->query($getZip);

                if ($getZipResult->num_rows > 0) {
                    // output data of each row
                    while($getZipRow = $getZipResult->fetch_assoc()) {

                        $vendor_lat = $getZipRow['lat'];
                        $vendor_lng = $getZipRow['lng'];

                        $link = '<a href="applicantProfile.php?appID='.$row["vendorAppID"].'">';
                        echo '

                        // add Vendor marker
                        map.addMarker({
                            lat: '.$vendor_lat.',
                            lng: '.$vendor_lng.',
                            title: "'.$row["fName"].' '.$row["lName"].'",
                            infoWindow: {
                                content: "'.$row["fName"].' '.$row["lName"].' is a '.$row["vendorType"].' in '.$row["city"].', '.$row["state"].'."
                            }
                        });
                        ';
                    }
                }
            }
        }
        ?>
    });
</script>

1 Answers1

4

Your code doesn't show an attempt to add a circle but here is how you can do it:

The Circle has a radius and a center property:

radius | Type: number - The radius in meters on the Earth's surface

center | Type: LatLng - The center

Check the Reference.

So you will need to convert your value from miles to meters: http://www.metric-conversions.org/length/miles-to-meters.htm

Example:

var cityCircle = new google.maps.Circle({
    strokeColor: '#FF0000',
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: '#FF0000',
    fillOpacity: 0.35,
    map: map,
    center: new google.maps.LatLng(10,20), // replace lat (10) and lng (20) with your $vendor_lat and $vendor_lng values
    radius: radius // your converted value from miles to meters
});

Edit:

As you are using Gmaps check the reference here: https://hpneo.github.io/gmaps/documentation.html#GMaps-drawCircle

So I guess you should use map.drawCircle()

map.drawCircle({
    lat: '.$vendor_lat.',
    lng: '.$vendor_lng.',
    radius: radius // your converted value from miles to meters
    // other options go here (see below)
});

All the other options you can use as per the google maps reference as the gmaps documentation mentions the following:

drawCircle accepts any option defined in google.maps.CircleOptions and any event defined in google.maps.Circle ('Events' section).

Community
  • 1
  • 1
MrUpsidown
  • 21,592
  • 15
  • 77
  • 131