NOVINKA - Online rekvalifikační kurz Python programátor. Oblíbená a studenty ověřená rekvalifikace - nyní i online.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

Google API maps

Z aktuální pozice na dané místo

if (navigator.geolocation) { //Checks if browser supports geolocation
    navigator.geolocation.getCurrentPosition(function(position) { //This gets the
        var latitude = position.coords.latitude; //users current
        var longitude = position.coords.longitude; //location
        var coords = new google.maps.LatLng(latitude, longitude); //Creates variable for map coordinates
        var directionsService = new google.maps.DirectionsService();
        var directionsDisplay = new google.maps.DirectionsRenderer();

        var mapOptions = //Sets map options
            {
                zoom: 15, //Sets zoom level (0-21)
                center: coords, //zoom in on users location
                mapTypeControl: true, //allows you to select map type eg. map or satellite
                navigationControlOptions: {
                    style: google.maps.NavigationControlStyle.SMALL //sets map controls size eg. zoom
                },
                mapTypeId: google.maps.MapTypeId.ROADMAP //sets type of map Options:ROADMAP, SATELLITE, HYBRID, TERRIAN
            };

        map = new google.maps.Map( /*creates Map variable*/ document.getElementById("map"), mapOptions /*Creates a new map using the passed optional parameters in the mapOptions parameter.*/ );
        directionsDisplay.setMap(map);
        directionsDisplay.setPanel(document.getElementById('panel'));
        var request = {
            origin: coords,
            destination: 'Zlín',
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        };

        var markers = [];

        /*vytvoření ukazatele*/
        markers[0] = new google.maps.Marker({
            position: {
                lat: 49.222616,
                lng: 17.662709
            },
            map: map,
            title: 'Parkoviště OD Prior' //popisek po najetí myší
        });

        //vykonání funkce po kliknutí na tento ukazatel
        google.maps.event.addListener(markers[0], 'click', function() {
            var infowindow = new google.maps.InfoWindow({
                content: "<b>Parkoviště OD Prior<b>"
            });
            infowindow.open(map, markers[0]);
        });

        markers[1] = new google.maps.Marker({
            position: {
                lat: 49.222151,
                lng: 17.660175
            },
            map: map,
            title: 'Parkoviště Velké kino'
        });

        google.maps.event.addListener(markers[1], 'click', function() {
            var infowindow = new google.maps.InfoWindow({
                content: "<b>Parkoviště Velké kino<b>"
            });
            infowindow.open(map, markers[1]);
        });

        markers[2] = new google.maps.Marker({
            position: {
                lat: 49.221068,
                lng: 17.658839
            },
            map: map,
            title: 'Parkoviště Březnická'
        });

        google.maps.event.addListener(markers[2], 'click', function() {
            var infowindow = new google.maps.InfoWindow({
                content: "<b>Parkoviště Březnická<b>"
            });
            infowindow.open(map, markers[2]);
        });

        /*konec ukazatelů*/

        directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                directionsDisplay.setDirections(response);
            }
        });
    });
}

Neformátovaný

Přidáno: 3.3.2017
Expirace: Neuvedeno

Avatar
Autor: Tomáš
Aktivity