Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:11:43+00:00 2026-06-10T09:11:43+00:00

I wrote a piece of code with Google Map to realize the location and

  • 0

I wrote a piece of code with Google Map to realize the location and GPS function.
But the navigation route always can’t shows,I don’t konw where is wrong?
Ask for help.Who can help me?
Thank you!

javascript code

<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) {  

        directionsDisplay = new google.maps.DirectionsRenderer();  

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

        };  

        map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);  
        directionsDisplay.setMap(map);  
        // 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>  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:11:44+00:00Added an answer on June 10, 2026 at 9:11 am

    i have worked out
    this piece of code is wrong

        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        
    }   
    

    i direct

    // Location found, show map with these coordinates    
    drawMap(defaultLatLng);  
    calcRoute(defaultLatLng); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a piece of code and used map and vector but it shows
I wrote this piece of code to my bootstrap public function _initRouter() { $pages
I've wrote a piece of code, but I am confused with its output: #include
i want to use google chart map which is a piece of javascript code
I wrote this piece of code that is supposed to redirect something written on
I wrote a little piece of code to expose my problem. public class date
I've wrote this simple piece of code. And I have a slight problem with
I wrote a same(..similar?) piece of code for Java 7 and C#(.net 3.5) and
I have a program I wrote in Windows with this piece of code that
I wrote this piece of code that lists all JPG files in the current

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.