/**
 * Created by User2 on 4/7/2015.
 */
var x = document.getElementById("map_holder");
getLocation();
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition, showError);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    var s = document.querySelector('#status');

    if (s.className == 'success') {
        // not sure why we're hitting this twice in FF, I think it's to do with a cached result coming back
        return;
    }

    s.innerHTML = "<div><br/>Found you!</div>";
    s.className = 'success';

    document.querySelector("#mapcanvas").style.height='300px';
    var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    var myOptions = {
        zoom: 15,
        center: latlng,
        mapTypeControl: false,
        navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);

    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title:"You are here! (at least within a "+position.coords.accuracy+" meter radius)"
    });
}


function showError(error) {
    switch (error.code) {
        case error.PERMISSION_DENIED:
            x.innerHTML = "User denied the request for Geolocation."
            break;
        case error.POSITION_UNAVAILABLE:
            x.innerHTML = "Location information is unavailable."
            break;
        case error.TIMEOUT:
            x.innerHTML = "The request to get user location timed out."
            break;
        case error.UNKNOWN_ERROR:
            x.innerHTML = "An unknown error occurred."
            break;
    }
}

@@ -81,16 +81,25 @@
 lder%22);%0A
+var map;%0A
 getLocat
@@ -368,299 +368,8 @@
 ) %7B%0A
-    var s = document.querySelector('#status');%0A%0A    if (s.className == 'success') %7B%0A        // not sure why we're hitting this twice in FF, I think it's to do with a cached result coming back%0A        return;%0A    %7D%0A%0A    s.innerHTML = %22%3Cdiv%3E%3Cbr/%3EFound you!%3C/div%3E%22;%0A    s.className = 'success';
 %0A%0A  
@@ -763,19 +763,16 @@
  %7D;%0A    
-var
  map = n
@@ -1027,18 +1027,818 @@
     %7D);%0A
-%7D
 %0A
+    var request = %7B%0A        location: latlng,%0A        radius: 500,%0A        types: %5B'store'%5D%0A    %7D;%0A    infowindow = new google.maps.InfoWindow();%0A    var service = new google.maps.places.PlacesService(map);%0A    service.nearbySearch(request, callback);%0A%7D%0A%0Afunction callback(results, status) %7B%0A    if (status == google.maps.places.PlacesServiceStatus.OK) %7B%0A        for (var i = 0; i %3C results.length; i++) %7B%0A            createMarker(results%5Bi%5D);%0A        %7D%0A    %7D%0A%7D%0A%0Afunction createMarker(place) %7B%0A    var placeLoc = place.geometry.location;%0A    var marker = new google.maps.Marker(%7B%0A        map: map,%0A        position: place.geometry.location%0A    %7D);%0A%0A    google.maps.event.addListener(marker, 'click', function() %7B%0A        infowindow.setContent(place.name);%0A        infowindow.open(map, this);%0A    %7D);%0A%7D
 %0A%0Afuncti

add a marker