„Get out form smog” – display the station

Get out from smog – part IX

To view the location where user should go I need to return adress station in Json. So I have to edit my controller so that it returns json.

Insead of return View i replaced:

return Json(new { station = leastPollutedPlace.StationLocation });

And I also modified the script to display the address of this station on view.

<script type="text/javascript">
    function getLocation() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function (position) {
                var _range= parseFloat($(".range").val());
                $.ajax({
                    url: '@Url.Action("Coordinate", "Home")',
                    data: { 'lat': position.coords.latitude, 'lon': position.coords.longitude,'range' :  _range},
                    type: "post",
                    cache: false,
                    success: function (response) {
                        $( "#position" ).text(response.station);                     
                    },
                    error: function (thrownError) {
                        alert('Something was wrong');                       
                    }
                });
            });
        }
    };
</script>

The change concerns this place:

success: function (response) {
 $( "#position" ).text(response.station);                     
},

To a div called position, I type the address of the station so the user can see it.

get out from smog

In the next step I will try to use google map application to display the station address.

Link to project.

Leave a Reply

Your email address will not be published. Required fields are marked *