-1

Geolocation を使用してユーザーの位置を特定し、ユーザーの位置と修正点の間をナビゲートしたいのですが、Google マップはナビゲートできず、Google の公式ドキュメントのコードを使用しています!

どうしたの?何千回も試した後、私は怒っています、助けてください

   <script type="text/javascript">

    $( "#map-page" ).live( "pageinit", function() {

        var directionsDisplay;
        var directionsService = new google.maps.DirectionsService();
        var map;
        var salon = new google.maps.LatLng(22.981666,120.194301);
        var defaultLatLng = new google.maps.LatLng(22.983587,120.22599);  // Default to Hollywood, CA when no geolocation support

        if ( navigator.geolocation ) {
            function success(pos) {
                // Location found, show map with these coordinates
                drawMap(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
                calcRoute(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));

            }

            function fail(error) {
                console.log(error);
                drawMap(defaultLatLng);  // Failed to find location, show default map
            }

            // Find the users current position.  Cache the location for 5 minutes, timeout after 6 seconds
            navigator.geolocation.getCurrentPosition(success, fail, {maximumAge: 500000, enableHighAccuracy:true, timeout: 6000});
        } else {
            drawMap(defaultLatLng);  // No geolocation support, show default map    
        }

        function drawMap(latlng) {
            var myOptions = {
                zoom: 10,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP

            };

            var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);

            // Add an overlay to the map of current lat/lng
            var marker = new google.maps.Marker({
                position: latlng,
                map: map,
                title: "Greetings!"
            });

            var marker = new google.maps.Marker({
                position:new google.maps.LatLng(22.981666,120.194301),
                map:map,
                title:"the salon"
            });
        }

        function calcRoute(latlng) {
        var start = latlng;
        var end = new google.maps.LatLng(22.981666,120.194301);
        var request = {
            origin:start,
            destination:end,
            travelMode: google.maps.TravelMode.DRIVING
        };
        directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
        }
      });
    }


    });


        </script>
4

1 に答える 1

0

設定するのを忘れましたdirectionsDisplay

于 2012-08-08T22:24:20.340 に答える