<commit_before>var map;
var service;
var actualPosition;
var markers = [];
var defaultMarkerColor = "FE7569";
var somePlaceIsSelected = false;


function initMap() {
    var myLatLng = {lat: 52.54063980000001, lng: -1.8916148000000703};
    var mapDiv = document.getElementById('map');
    map = new google.maps.Map(mapDiv, {
        center: myLatLng,
        zoom: 16
    });

    var infoWindow = new google.maps.InfoWindow({map: map});

    // Try HTML5 geolocation.
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
            actualPosition = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
            };
            createMarkerOnMap(actualPosition, "Vaše poloha", "FFFFFF")

            map.setCenter(actualPosition);
            console.log("map initialized");

            document.getElementById('radius-input').addEventListener('change', getNearbyLocations);
            getNearbyLocations();
        }, function() {
            handleLocationError(true, infoWindow, map.getCenter());
        });
    } else {
        // Browser doesn't support Geolocation
        handleLocationError(false, infoWindow, map.getCenter());
    }
}

function handleLocationError(browserHasGeolocation, infoWindow, pos) {
    infoWindow.setPosition(pos);
    infoWindow.setContent(browserHasGeolocation ?
        'Error: The Geolocation service failed.' :
        'Error: Your browser doesn\'t support geolocation.');
}

function getNearbyLocations() {
    for( var i = 0; i < markers.length; i++ ) {
        markers[i].setMap(null);
    }
    markers = [];
    var request = {
        location: actualPosition,
        radius: document.getElementById('radius-input').value,
        types: ['restaurant', 'food'],
    };
    service = new google.maps.places.PlacesService(map);
    service.nearbySearch(request, markNearbyPlaces);
}

function markNearbyPlaces(results, status) {
    if (status == google.maps.places.PlacesServiceStatus.OK) {
        var userId = localStorage.getItem("id");
        var userPlaces;
        if(userId != null && userId != undefined){
            makeCorsRequest("GET", "https://ivebeenthereapi-matyapav.rhcloud.com/places/"+userId, null, function (responseText) {
                if(responseText){
                    userPlaces = JSON.parse(responseText);
                }
                results.forEach(function (v,i) {
                    var place = results[i];
                    var marker = createMarkerOnMap(place.geometry.location, place.name, defaultMarkerColor );
                    markers.push(marker);
                    marker.addListener('click', function(){
                        markers.forEach(function (v,i) {
                            userPlaces.forEach(function (userPlace) {
                                if(userPlace.name == place.name){
                                    setMarkerColor(marker, "00ff00");
                                }else{
                                    setMarkerColor(markers[i], defaultMarkerColor)
                                }
                            });
                        });
                        setMarkerColor(marker, "7f3a34")
                        showInfoAboutPlace(place);
                    });
                });
            });
        }else{
            results.forEach(function (v,i) {
                var place = results[i];
                var marker = createMarkerOnMap(place.geometry.location, place.name, defaultMarkerColor );
                markers.push(marker);
                marker.addListener('click', function(){
                    markers.forEach(function (v,i) {
                        setMarkerColor(markers[i], defaultMarkerColor)
                    });
                    setMarkerColor(marker, "7f3a34")
                    showInfoAboutPlace(place);
                });
            });
        }
    }
}

function createMarkerOnMap(position, title, pinColor) {<commit_msg>Implementing "I was there" action #5.5<commit_after>var map;
var service;
var actualPosition;
var markers = [];
var defaultMarkerColor = "FE7569";
var somePlaceIsSelected = false;


function initMap() {
    var myLatLng = {lat: 52.54063980000001, lng: -1.8916148000000703};
    var mapDiv = document.getElementById('map');
    map = new google.maps.Map(mapDiv, {
        center: myLatLng,
        zoom: 16
    });

    var infoWindow = new google.maps.InfoWindow({map: map});

    // Try HTML5 geolocation.
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
            actualPosition = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
            };
            createMarkerOnMap(actualPosition, "Vaše poloha", "FFFFFF")

            map.setCenter(actualPosition);
            console.log("map initialized");

            document.getElementById('radius-input').addEventListener('change', getNearbyLocations);
            getNearbyLocations();
        }, function() {
            handleLocationError(true, infoWindow, map.getCenter());
        });
    } else {
        // Browser doesn't support Geolocation
        handleLocationError(false, infoWindow, map.getCenter());
    }
}

function handleLocationError(browserHasGeolocation, infoWindow, pos) {
    infoWindow.setPosition(pos);
    infoWindow.setContent(browserHasGeolocation ?
        'Error: The Geolocation service failed.' :
        'Error: Your browser doesn\'t support geolocation.');
}

function getNearbyLocations() {
    for( var i = 0; i < markers.length; i++ ) {
        markers[i].setMap(null);
    }
    markers = [];
    var request = {
        location: actualPosition,
        radius: document.getElementById('radius-input').value,
        types: ['restaurant', 'food'],
    };
    service = new google.maps.places.PlacesService(map);
    service.nearbySearch(request, markNearbyPlaces);
}

function markNearbyPlaces(results, status) {
    if (status == google.maps.places.PlacesServiceStatus.OK) {
        var userId = localStorage.getItem("id");
        var userPlaces;
        if(userId != null && userId != undefined){
            makeCorsRequest("GET", "https://ivebeenthereapi-matyapav.rhcloud.com/places/"+userId, null, function (responseText) {
                if(responseText){
                    userPlaces = JSON.parse(responseText);
                }
                results.forEach(function (v,i) {
                    var place = results[i];
                    var marker = createMarkerOnMap(place.geometry.location, place.name, defaultMarkerColor );
                    markers.push(marker);
                    marker.addListener('click', function(){
                        markers.forEach(function (v,i) {
                            userPlaces.forEach(function (userPlace) {
                                if(userPlace != null) {
                                    if (userPlace.name == place.name) {
                                        setMarkerColor(marker, "00ff00");
                                    } else {
                                        setMarkerColor(markers[i], defaultMarkerColor)
                                    }
                                }
                            });
                        });
                        setMarkerColor(marker, "7f3a34")
                        showInfoAboutPlace(place);
                    });
                });
            });
        }else{
            results.forEach(function (v,i) {
                var place = results[i];
                var marker = createMarkerOnMap(place.geometry.location, place.name, defaultMarkerColor );
                markers.push(marker);
                marker.addListener('click', function(){
                    markers.forEach(function (v,i) {
                        setMarkerColor(markers[i], defaultMarkerColor)
                    });
                    setMarkerColor(marker, "7f3a34")
                    showInfoAboutPlace(place);
                });
            });
        }
    }
}

function createMarkerOnMap(position, title, pinColor) {
{'fraction_non_alphanumeric': 0.11044593769089799, 'fraction_numerical': 0.013194868662186927, 'mean_word_length': 1.761808367071525, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '266804', 'n_tokens_mistral': 2228, 'n_tokens_neox': 2078, 'n_words': 382}