Google Maps, doubt about marker radius overlay

2

I implemented the Maps API v3 in Javascript on a reservation system, in the system I used PHP to connect to the MySQL database to return the units of a franqueadora that already exist and are operating, and also made available on the same screen a field of search for the address query to check whether the address already exists or not a unit franked within a radius of 1,500 meters, so far so good, franqueadas in operation has a radius of 1,500 meters white, and registered addresses as reserves have the radius of 1,500 meters in the green color, but there was a need, when a reserve overlaps the radius of an existing franchise in operation, have the radius color changed from green to red to signal the overlap. >

The screen displays the franchisees operating with their radius, the reserves with their radius, is working perfectly, however I consulted the documentation of the Google Maps API and for being extensive I might not find or do not know if they make this feature available, would like the help of the community to heal this doubt, whether it is possible to change the color of the ray of a superimposed marker, and if so, if there is an example of someone who has already done so. Here is the image of the current one:

Thereisstandardintegration,greenraymarkingsarea"var location" for reservations only, and a "var location" for only places that are already running. I need to see how to change the color of the "var location" of the green rays when they are overlapped with those of white ray.

The written code follows. The code includes address lookup, map, markers, and API integration code:

    
<link href="https://code.jquery.com/ui/1.10.4/themes/dark-hive/jquery-ui.css" rel="stylesheet" media="all">
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"integrity="sha256-xI/qyl9vpwWFOXz7+x/9WkG5j/SVnSw21viy8fWwbeE=" crossorigin="anonymous"></script>



<script type="text/javascript">

        var geocoder;
        var map;
        var marker;
        var image = 'https://www.crosslife.info/painel/assets/images/mark-teste.png';

        var locations2 = [

            ['RESERVA: ', -23.9446791, -46.3264323, 'Av. Senador Feijó, 421 - Vila Nova, Santos - SP, 11013-162, Brasil'],
['RESERVA: ', , , 'R. Assunção, 414 - Sion, Belo Horizonte - MG, 30320-040, Brasil'],
['RESERVA: ', , , 'R. Padre Feijó, 373 - Vila Tiberio, Ribeirão Preto - SP, 14050-360, Brasil'],
['RESERVA: ', , , 'R. Vitoriano Salut, 72 - Chácara Belvedere, Indaiatuba - SP, Brasil'],
['RESERVA: ', -20.8873894, -47.5997438, 'Rua Ana Luiza, 197 - Bairro Castelo, Batatais - SP, 14300-000, Brasil']

        ]


        var locations = [
            ['Vila Osasco', -23.544559, -46.781034, 'Avenida Santo Antônio, 2761, Vila Osasco,  - SP, 06083-215, Brasil'],
['Rebouças', -22.8904057, -43.5603237, 'Avenida Rebouças, 3657, Centro,  - SP, 13170-023, Brasil'],
['Nutrition Bauru', -22.3370765, -49.0891827, 'Avenida Castelo Branco, 7-15, Vila Independência,  - SP, 17052-000, Brasil'],
['Pitangueiras', -23.2022764, -46.8836439, 'Rua Pitangueiras, 790, Jardim Pitangueiras,  - SP, 13206-716, Brasil'],
['Nutrition Vale do Sol', -20.4229151, -49.9592271, 'Avenida pansani, 3092, Vale do sol,  - SP, 15500-302, Brasil'],
['Cidade Nova Montes Claros-Mg', -16.739527, -43.8653989, 'Avenida Dona Gregória, 101, Cidade Nova,  - MG, 39400-464, Brasil'],
['Centro Salto', -23.199741, -47.3008818, 'Avenida Dom Pedro II, 1421, Centro,  - SP, 13320-241, Brasil'],
['ASSIS', -22.6575047, -50.397561, 'Rua Antônio da Silva Cunha Bueno, 425, Jardim Paulista,  - SP, 19815-080, Brasil'],
['Paulinia', -22.743178, -47.1744984, 'Avenida João Aranha, 946, Alto de Pinheiros,  - SP, 13145-256, Brasil'],
['SBC Centro', -23.7132318, -46.5532384, 'Rua Joaquim Nabuco, 56, Centro,  - SP, 09720-375, Brasil'],
['- Chácara', -23.6290144, -46.7025941, 'Rua da paz, 1498, Chácara Santo Antônio,  - SP, 04713-000, Brasil'],
['Nova Europa', -22.9424831, -47.0573369, 'Avenida Baden Powell, 1831, Nova Europa,  - SP, 13040-093, Brasil'],
['Morada do Sol', -23.1269188, -47.244239, 'Rua João Martini, 475, Jardim Morada do Sol,  - SP, 13348-350, Brasil'],
['campo grande RJ', -22.890374, -43.560187, 'Rua do petróleo, 14, Campo Gande,  - RJ, 23087-125, Brasil'],
['Tremembé', -23.4587589, -46.6149244, 'Avenida Nova Cantareira, 4794, Tucuruvi,  - SP, 02340-002, Brasil'],
['Crosslife Nutrition Vila das Belezas', -23.6491279, -46.7543918, 'Estrada de Itapecerica, 2219, Vila das Belezas,  - SP, 05835-005, Brasil'],
['Centro', -23.0854053, -47.2105986, 'Rua Humaitá, 1099, Centro,  - SP, 13339-140, Brasil'],
['ITAPECERICA', -23.698334, -46.8527042, 'Rua Ari Batalha, 393, Parque Paraiso,  - SP, 06850-335, Brasil'],
['lapa', -23.5250071, -46.6872423, 'Rua Clélia, 911, Lapa,  - SP, 05042-000, Brasil'],
['Cross life', -17.7718674, -48.6186493, 'Rua B-02, S/N, Estância Itanhanga,  - GO, 75690-000, Brasil'],
['Tatuapé', -23.552282, -46.5566401, 'Rua Francisco Marengo, 1717, Tatuapé,  - SP, 03313-001, Brasil'],
['Flamboyant', -22.8762222, -47.0358206, 'Rua Comendador Doutor Antônio Pompeo Camargo, 104, Jardim Boa Esperança,  - SP, 13091-502, Brasil'],
['N.Sr de Fatima', -22.8975439, -47.1685964, 'Armelinda Espúrio da Silva, 565, Jardim Nossa Senhora de Fátima,  - SP, 13084-450, Brasil'],
['Agapeama', -23.2053398, -46.8651296, 'Rua da Varzea Paulista, 487, Vila Agricola,  - SP, 13202-700, Brasil'],
['Buriti', -23.2230818, -46.8760877, 'Rua Dom Pedro I, 462, Jardim Buriti,  - SP, 13225-790, Brasil'],
['BOA VISTA', -14.8793362, -40.832031, 'Avenida Gilenilda Alves, 1345, Boa Vista,  - BA, 45027-560, Brasil'],
['CROSS TRAINING - FABRICA DE RESULTADOS', -23.6008617, -46.8988726, 'Rua Pinhal, 83, Jardim Sabia,  - SP, 06716-575, Brasil'],
['Valentina Cross Life', -16.7287284, -43.8835938, 'Rua Espírito Santo Esplanada, 395, Esplanada,  - MG, 39401-452, Brasil'],
['PEDRO PINHO', -23.5402247, -46.8010548, 'Avenida General Pedro Pinho, 1052, Pestana,  - SP, 06122-160, Brasil'],
['Vicente Pires', -15.8095347, -48.0159685, 'Rua 4 A, 24, Vicente Pires,  - DF, 72006-206, Brasil'],
['Crosslife 9 de Julho', -23.1939338, -47.2850897, 'Avenida 9 de julho, 1733, Vila Roma,  - SP, 13321-560, Brasil'],
['Rr soluções comerciais', -23.6212842, -46.6887282, 'Rua Oscar Gomes Cardim, 37, Vila cordeiro,  - SP, 04580-040, Brasil'],
['Cross Life', -15.8382146, -48.0222926, 'Rua 17 norte, 3, Águas Claras Norte,  - DF, 71910-540, Brasil'],
['Jd.europa', -23.0715471, -47.2270102, 'Alameda José Amstalden, 1173, Jardim Europa,  - SP, 13331-100, Brasil'],
['Colibris', -23.1279811, -47.2494992, 'Guaianazes, 94, Jardim Colibris,  - SP, 13349-820, Brasil'],
['várzea centro', -23.2131507, -46.8458156, 'Avenida José Rabelo Portela, 276, Jardim Maria de Fátima,  - SP, 13220-540, Brasil'],
['CROSS LIVE GUARAPIRANGA', -23.670636, -46.7389666, 'Estrada do M boi Mirim, 609, Jardim das Flores,  - SP, 04905-020, Brasil'],
['Jaguare -SP', -23.5504009, -46.7483687, 'Avenida Presidente Altino, 602, Jaguare,  - SP, 05335-120, Brasil'],
['Cidade Nova', -20.5294527, -47.3930331, 'Rua Frederico Moura, 1650, Cidade Nova,  - SP, 14401-150, Brasil'],
['Consolação', -20.5478245, -47.4040117, 'Rua Chile, 1521, Jardim Consolação,  - SP, 14400-110, Brasil'],
['Piratininga', -20.5421062, -47.3746126, 'Avenida Hugo Betarello, 3580, Piratininga,  - SP, 14403-219, Brasil'],
['Delfino', -16.7419277, -43.8419136, 'Avenida Neco Delfino, 1034, Delfino Magalhães,  - MG, 39402-181, Brasil'],
['Nutrition', -5.8911932, -35.2064656, 'Avenida Maria Lacerda, 8792, Nova Parnamirim,  - RN, 59152-600, Brasil'],
['Avenida São Vicente', -20.5510118, -47.3871382, 'Avenida São Vicente, 3455, Jd. Noêmia,  - SP, 14403-720, Brasil'],
['CrossLife São Luiz - Itu', -23.271317, -47.2831139, 'Rua Gabriel de Bourbon y Bourbon, 45, São Luiz,  - SP, 13304-060, Brasil'],
['Adhemar de Barros', -20.5156199, -47.3729824, 'Avenida Adhemar Pereira de Barros, 301, Jardim Eden,  - SP, 14402-250, Brasil'],
['Santa Inês BH', -19.8862532, -43.9090425, 'Rua Vicente Risola, 660, Santa Inês,  - MG, 31080-160, Brasil'],
['Cross Life', -22.8676863, -47.2244041, 'Avenida Olívio Franceschini, 1900, Parque Ortolândia,  - SP, 13184-160, Brasil'],
['Lopes assessoria esportiva', -22.8384459, -47.1588462, 'Avenida Minasa, 1195, Vila San Martin,  - SP, 13180-165, Brasil'],
['CASSIOPÉIA', -23.2290628, -45.8878066, 'Avenida Cassiopéia, 678, Jardim Satélite,  - SP, 12230-010, Brasil'],
['Unidade Dompieri', -20.5173041, -47.3975326, 'Avenida Orlando Dompieri, 1820, Jardim Barão,  - SP, 14409-003, Brasil'],
['Casa Verde', -23.5117625, -46.6508895, 'Rua Brazelisa Alves de Carvalho, 431, Vila Baruel,  - SP, 02510-030, Brasil'],
['Team - Vila Yara', -23.5459214, -46.7639022, 'Rua Moema, 49, Vila Yara,  - SP, 06028-280, Brasil'],
['Jardim dos Ipês', -23.280734, -47.3069559, 'Avenida Caetano Ruggieri, 4006, Jardim dos Ipês,  - SP, 13311-440, Brasil'],
['Crosslife - Av Brasil', -20.5266837, -47.379848, 'Avenida Brasil, 1262, Vila Aparecida,  - SP, 14401-240, Brasil'],
['Grajaú', -23.7355639, -46.69432, 'Rua Leri Santos, 194, Grajaú,  - SP, 04822-290, Brasil'],
['Aeroporto', -20.5752957, -47.3673357, 'Rua Cyro Eduardo Rosa Faleiros, 1158, Aeroporto 2,  - SP, 14404-091, Brasil'],
['Eloy Chaves', -23.1898838, -46.9623624, 'Rua Doutor Ângelo Pernambuco, 130, Eloy Chaves,  - SP, 13212-123, Brasil'],
['Independência', -16.719114, -43.8253718, 'Rua Lagoa das Palmas, 404, Carmelo,  - MG, 39402-729, Brasil'],
['Guanabara', -22.8896133, -47.0600126, 'Rua Rafael Sampaio, 187, Guanabara,  - SP, 13023-240, Brasil'],
['Nutrition', -22.9240667, -47.081058, 'Rua Manuel Francisco Monteiro, 38, Parque Industrial,  - SP, 13031-500, Brasil'],
['CROSSLIFE NUTRITION', -18.935402, -48.2457239, 'Avenida João Mendes, 631, Pampulha,  - MG, 38408-660, Brasil'],
['Cross Life', -23.5954744, -46.8486695, 'Avenida Elias zarzur, 147, Parque São George,  - SP, 06708-210, Brasil'],
['marajoara', -23.6640911, -46.6872448, 'Rua Roque Giangrande filho, 68, Jardim marajoara,  - SP, 04674-110, Brasil'],
['Valinhos', -22.9623421, -46.9786923, 'Rua Lino Buzatto, 855, Jardim Pinheiros,  - SP, 13274-440, Brasil'],
['nutriton', -5.8005449, -35.203111, 'Rua Joaquim Fagundes, 688, Barro vermelho,  - RN, 59022-500, Brasil'],
['Via Norte', -22.875639, -47.129895, 'Rua Renato Ribeiro, 33, Pq Via Norte,  - SP, 13065-707, Brasil'],
['Campos Elíseos', -22.9292555, -47.1019142, 'Avenida Paulo Provenza Sobrinho, 125, Campos Elíseos,  - SP, 13060-864, Brasil'],
['VILA GUILHERME', -23.5034688, -46.6047706, 'Rua Lagoa Panema, 543, Vila Guilherme,  - SP, 02051-050, Brasil'],
['Itaici', -23.1045439, -47.1825595, 'Av.Coronel Antonio Estanislau do Amaral, 1305, Jardim Juliana,  - SP, 13335-410, Brasil'],
['Meira Junior', -21.1768859, -47.7974337, 'Av. Meira Júnior, 520, Jd Paulusta,  - SP, 14090-003, Brasil'],
['Crosslife Cintra', -16.7296067, -43.8499477, 'Av Coronel Luiz Maia, 616, Cintra,  - MG, 39401-486, Brasil'],
['Casa Verde', -23.5117632, -46.6508951, 'Rua Brazelisa Alves de Carvalho, 431, Casa Verde,  - SP, 02510-030, Brasil'],
['Nutrition', -23.085744, -47.1850339, 'Rua: Antônio Martins Rosa, 24, Vila Homero,  - SP, 13338-740, Brasil'],
['NUTRITION TANCREDAO', -22.9387375, -47.0970644, 'R NELLY BONTORE, 343, JD SANTA AMALIA,  - SP, 13050-114, Brasil'],
['RIO BONITO', -23.6814618, -46.7054199, 'Av. do Rio Bonito, 974, Socorro,  - SP, 04776-001, Brasil'],
['Juiz de Fora', -21.762771, -43.345585, 'Avenida Presidente Itamar Franco, 676, Centro,  - MG, 36010-020, Brasil'],
['Nutrition Jardim do Trevo', -22.9248287, -47.0658387, 'Rua Fernão Pompeo de Camargo, 1079, Jardim do Trevo,  - SP, 13040-010, Brasil'],
['Crosslife Campo Limpo', -23.645127, -46.7638252, 'Estrada do Campo Limpo, 2722, Campo Limpo,  - SP, 05777-000, Brasil'],
['14 de DEZEMBRO', -23.2129867, -46.8745139, 'Av. 14 de Dezembro, 1440, Vila Mafalda,  - SP, 0, Brasil'],
['não tem', -22.7405319, -47.3042479, 'Avenida Geraldo Gobbo, 233, Santa Cruz,  - SP, 13477-410, Brasil'],
['João Dias', -23.6451097, -46.7158278, 'Avenida João Dias, 1601, Santo Amaro,  - SP, 04724-002, Brasil'],
['Plaza Itu-SP', -23.2639438, -47.2790414, 'avenida plaza, 182, jardim paraiso,  - SP, 13302-100, Brasil'],
['PARK', -23.1520141, -46.9211165, 'Av Professor Pedro Clarismundo Fornari, 915, Engordadouro,  - SP, 13214-660, Brasil'],
['Swift', -22.9310774, -47.0381773, 'Av Jorge Tibiriça, 551, Swift,  - SP, 13096-550, Brasil'],
['CROSSLIFEJANAUBA', -15.8163678, -43.3036, 'Av Manoel Athayde, 1060, Saudade,  - MG, 39445-281, Brasil'],
['PIRITUBA', -23.4926145, -46.7103305, 'Rua Custódio de Araújo, 80, VILA PEREIRA CERCA,  - SP, 02932-050, Brasil'],
['SF', -19.9442866, -43.9787316, 'Rua Maquiné, 580, Salgado Filho,  - MG, 30550-176, Brasil'],
[Mogi Guaçu', -22.3421956, -46.9482555, 'Avenida Bandeirantes, 1890, Ypê IV,  - SP, 13846-010, Brasil'],
['Nova Gerty', -23.6392394, -46.5665469, 'Rua Nelly Pellegrino, 707, Nova Gerty,  - SP, 09580-140, Brasil'],
['Terramérica', -22.768215, -47.356709, 'Av. Padre Oswaldo Vieira de Andrade, 569, Terramérica,  - SP, 13468-821, Brasil'],
['LIfe Mogi', -23.5184754, -46.1741309, 'Rua Adriano Cezar Pinto, 83, Socorro,  - SP, 08780-590, Brasil'],
['varzea centro', -23.2131507, -46.8458156, 'av jose rabelo portela, 276, jd maria de fatima,  - SP, 13220-520, Brasil'],
['Saguaçu Joinville', -26.2791381, -48.8460482, 'Rua Aluísio Pires Condeixa, 2700, Saguaçu,  - SC, 89221-008, Brasil'],
['ESCOLA DE DANCA E CONDICIONAMENTO FISICO RLUB', -23.7359969, -46.6947068, 'Rua Leri Santos, 194, Parque America,  - SP, 04822-290, Brasil'],
['BARÃO', -21.1433681, -47.9829966, 'Rua Barao do Rio Branco, 2064, Centro,  - SP, 14160-570, Brasil'],
['Life Autódromo', -23.695804, -46.6923545, 'av joao paulo da silva, 635, vila da paz,  - SP, 04777-020, Brasil'],
['Life Conceição', -23.6372361, -46.6401292, 'Praça Barao de Japura, 85, Vila Guarani,  - SP, 04313-170, Brasil'],
['TESTE', -23.1848975, -46.9710744, 'Rua Chiara Lubich,, 371, Jardim Ermida I,  - SP, 13212-117, Brasil'],
['RJ ANIL', -22.9568606, -43.3464518, 'Estrada do Engenho dagua, 1375, Anil,  - RJ, 22765-240, Brasil'],
['JARDIM DOM JOSÉ', -23.676669, -46.800363, 'Avenida Jundia, 374, Jardim Dom José,  - SP, 06824-010, Brasil'],
['Guarulhos', -23.3992557, -46.398908, 'Estrada Acácio Antônio Batista, 898, Bonsucesso,  - SP, 07175-080, Brasil'],
['Aclimação', -23.5800915, -46.6242578, 'Av. Lins de Vasconcelos, 1887, Aclimação,  - SP, 01537-001, Brasil'],
['LEPORACE', -20.4965275, -47.4218309, 'Av Abrão brickimam, 1651, LEPORACE,  - SP, 14407-010, Brasil'],
['Bonfiglioli SP', -23.5778294, -46.7438786, 'Av: Eng Heitor Ant. Eiras Garcia, 868, Jd Bonfiglioli,  - SP, 05588-001, Brasil'],
['Maracanã Litoral Paulista- Baixada Santista', -24.0375914, -46.5095634, 'Av. Presidente keneddy, 10.563, MARACANÃ,  - SP, 11705-755, Brasil'],
['mascote', -23.6431095, -46.6662527, 'Rua Palestina, 48, vila Mascote,  - SP, 04362-030, Brasil'],
['=Taguatinga Sul', -15.8107481, -48.065751, 'Qsa 12, loja 08, comercial sul, s/n, Taguatinga,  - DF, 72015-12, Brasil'],
['=VILA ISABE', -22.9188801, -43.2515651, 'Rua Teodoro da Silva, 675, Vila Isabel,  - RJ, 20560-002, Brasil'],
['=Angelica', -20.664223, -43.7866209, 'Rua Coronel Licinio Dutra, 263, Angelica,  - MG, 36400-031, Brasil'],
['=SÃO ROQUE', -29.1390673, -51.5226835, 'Tr JOSÉ RAMPANELLI, 275, SÃO ROQUE,  - RS, 95708-490, Brasil'],
['=Vila Leopoldina', -23.527816, -46.7334758, 'Av. Imperatriz Leopoldina, 609, Vila Leopoldina,  - SP, 05305-011, Brasil']
        ];

        function initMap() {

            var latlng = new google.maps.LatLng(-84.568808, -100.418683);

            var options = {
                zoom: 4,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            map = new google.maps.Map(document.getElementById("mapa"), options);

            geocoder = new google.maps.Geocoder();

            marker = new google.maps.Marker({
                map: map,
                zoom: 2
            });

            marker.setPosition(latlng);

            setMarkers(map,locations);

            setMarkers(map,locations2);

        }

        function setMarkers(map,locations){

            var marker, i

            for (i = 0; i < locations.length; i++) {  

                var loan = locations[i][0]
                var lat = locations[i][1]
                var long = locations[i][2]
                var add =  locations[i][3]

                latlngset = new google.maps.LatLng(lat, long);

                var marker = new google.maps.Marker({  
                    map: map,
                    title: loan,
                    position: latlngset,
                    icon: image
                });

                // Construct the circle for each value in citymap.
                // Note: We scale the area of the circle based on the population.
                for (var city in locations) {
                  // Add the circle for this city to the map.
                  var cityCircle = new google.maps.Circle({
                    map: map,
                    zoom: 2,
                    center: new google.maps.LatLng(lat, long),
                    radius: 750,
                    strokeColor: "#818c99",
                    fillColor: "#ffffff",
                    fillOpacity: 0.70
                  });
                }

                for (var city in locations2) {
                  // Add the circle for this city to the map.
                  var cityCircle = new google.maps.Circle({
                    map: map,
                    zoom: 2,
                    center: new google.maps.LatLng(lat, long),
                    radius: 750,
                    strokeColor: "#229A1F",
                    fillColor: "#49DA45",
                    fillOpacity: 0.50
                  });
                }

                map.setCenter(marker.getPosition())

                var content = "<h5>" + loan + '</h5>' + "<strong>Endereço:</strong> " + add;

                var infowindow = new google.maps.InfoWindow()

                google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){ 
                    return function() {
                        infowindow.setContent(content);
                        infowindow.open(map,marker);
                    };
                })(marker,content,infowindow));

            }

        }

        function carregarNoMapa(endereco) {
            geocoder.geocode({ 'address': endereco + ', Brasil', 'region': 'BR' }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[0]) {

                        var latitude = results[0].geometry.location.lat();
                        var longitude = results[0].geometry.location.lng();

                        $('#txtEndereco').val(results[0].formatted_address);
                        $('#txtLatitude').val(latitude);
                        $('#txtLongitude').val(longitude);

                        var location = new google.maps.LatLng(latitude, longitude);
                        marker.setPosition(location);
                        map.setCenter(location);
                        map.setZoom(16);
                        $('html,body').animate({scrollTop:$("#mapa").offset().top}, 800);
                    }
                }
            });
        }

        function excluirReserva(codigo) {
            if(confirm('Excluir reserva permanentemente?')){
                $.ajax({
                    type:'POST',
                    url: "_ajax/reservar-excluir.php",
                    data: {codigo: codigo},
                    success: function(data) {
                        $('#returnResponse').html(data);
                        console.log(data);
                    }
                });
            }
        }

        $("#btnEndereco").click(function() {
            if($(this).val() != "")
                carregarNoMapa($("#txtEndereco").val());
                $("#txtEnderecoReserva").val($("#txtEndereco").val());
                $("#btnSalvarReserva").show();
                $("#reservaLabel").show();
                $("#reservaLabel2").show();
        });

        $("#txtEndereco").blur(function() {
            if($(this).val() != "")
                carregarNoMapa($(this).val());

        });

        $("#txtEndereco").autocomplete({
            source: function (request, response) {
                geocoder.geocode({ 'address': request.term + ', Brasil', 'region': 'BR' }, function (results, status) {
                    response($.map(results, function (item) {
                        return {
                            label: item.formatted_address,
                            value: item.formatted_address,
                            latitude: item.geometry.location.lat(),
                            longitude: item.geometry.location.lng()
                        }
                    }));
                })
            },
            select: function (event, ui) {
                $("#txtLatitude").val(ui.item.latitude);
                $("#txtLongitude").val(ui.item.longitude);
                $("#txtEnderecoReserva").val(ui.item.label);
                var location = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
                marker.setPosition(location);
                map.setCenter(location);
                map.setZoom(16);
                $("#btnSalvarReserva").show();
                $("#reservaLabel").show();
                $("#reservaLabel2").show();
            }
        });

        /*$('html,body').animate({scrollTop:$("#mapa").offset().top}, 800);*/

        $(document).ready(function(){
            $('body').attr('onload', 'initMap();');

            $("#numeroUnidades").html('112 UNIDADES');

            $("#btnSalvarReserva").on('click', function(){

                var endereco = $("#txtEnderecoReserva").val();
                var latitude = $("#txtLongitude").val();
                var longitude = $("#txtLatitude").val();
                var reservaNome = $("#reserva_nome").val();
                var registro = $("#reserva_registro").val();

                $.ajax({
                    type:'POST',
                    url: "_ajax/reservar-endereco.php",
                    data: {endereco : endereco, latitude: latitude, longitude: longitude, nome: reservaNome, registro: registro},
                    success: function(data) {
                        $('#returnResponse').html(data);
                        console.log(data);
                    }
                });

            });

        });

  </script>
    
asked by anonymous 07.08.2018 / 02:49

1 answer

0

Use these functions to convert to radians, get the distance and check for intersection:

// Esta função vai converter graus para radianos
Number.prototype.toRadians = function() {
    return this * (Math.PI / 180.0);
};

function distance(lat0, long0, lat1, long1){

    // converter graus para radianos
    var rlat0 = lat0.toRadians();
    var rlong0 = long0.toRadians();
    var rlat1 = lat1.toRadians();
    var rlong1 = long1.toRadians();

    // calcular as diferenças para latitude e longitude (os deltas)
    var deltaLat = (rlat1-rlat0);
    var deltaLong = (rlong1-rlong0);

    // calcular a fórmula de uso grande haversine para calcular a distância do grande círculo entre dois pontos
    var a = Math.pow(Math.sin(deltaLat / 2), 2) + Math.pow( Math.sin(deltaLong / 2), 2) * Math.cos(rlat0) * Math.cos(rlat1);  

    // multiplica pelo raio do grande círculo (raio médio da terra em metros)
    return (2 * Math.asin(Math.sqrt(a))) * 6378137;
}

function hasIntersections(circle0,circle1){
    var center0 = circle0.getCenter();
    var center1 = circle1.getCenter();

    var maxDist = circle0.getRadius()+circle1.getRadius();
    var actualDist = distance(center0.lat(),center0.lng(),center1.lat(),center1.lng());

    return maxDist>=actualDist;
}

Now you just apply to your case, you keep all the circles in arrays , and you go through them and check for an intersection (untested example):

function setMarkers(map,locations){
//[....]

var circles = [];
var circles2 = [];
// Construct the circle for each value in citymap.
// Note: We scale the area of the circle based on the population.
for (var city in locations) {
  // Add the circle for this city to the map.
  var cityCircle = new google.maps.Circle({
    map: map,
    zoom: 2,
    center: new google.maps.LatLng(lat, long),
    radius: 750,
    strokeColor: "#818c99",
    fillColor: "#ffffff",
    fillOpacity: 0.70
  });
  //Adicionar circulo ao array
  circles.push(cityCircle);
}

for (var city in locations2) {
  // Add the circle for this city to the map.
  var cityCircle = new google.maps.Circle({
    map: map,
    zoom: 2,
    center: new google.maps.LatLng(lat, long),
    radius: 750,
    strokeColor: "#229A1F",
    fillColor: "#49DA45",
    fillOpacity: 0.50
  });

  //Adicionar circulo ao array
  circles2.push(cityCircle);
}

//Percorrer todos os circlos
for (var circle1 in circles) {
    for (var circle2 in circles2) {
        //Faz a verificação se os circulos tocam-se
        // Aqui alteras a cor desejada
        console.log(hasIntersections(circle1, circle2));
    }
}
    
13.08.2018 / 18:06