Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Javascript help for me cause I'm an idiot

  • 05-05-2007 01:24AM
    #1
    Registered Users, Registered Users 2 Posts: 3,484 ✭✭✭


    Note I'm using map24 cause yahoo doesnt give directions yet and googles resolution is still crap!

    Have a problem with my site at the moment, I'm trying to create a link, click to get locations to a fixed destination (Have the lat and long of the destination), where it brings you to a new page.

    When the new page opens I have to first convert the lat and long of the desitnation to an actual address, reverse geocoding:

    http://devnet.map24.com/manuals/doku.php?id=ajax:2.0:tutorials:geocoding:reversegeocoding

    Once I have this address, I then take the users address from a form and input both into a function to calculate the directions.

    http://devnet.map24.com/manuals/doku.php?id=ajax:2.0:tutorials:routing:routing

    My problem seems to be combining the two functions together

    You can see my code here:

    http://www.ratemypub.ie/directions.php?pubid=129

    Any help would be really really really appreciated as it's half two in the morning here in sweden and it's doing my head in!

    Thanks
    Gary

    I really don't have a notion about javascript so any help would be appreciated:


Comments

  • Registered Users, Registered Users 2 Posts: 3,484 ✭✭✭randombar


    Can anyone help me with this one? I just don't have a clue about javascript!


  • Registered Users, Registered Users 2 Posts: 11,985 ✭✭✭✭zAbbo


    your page crashes FF for me


  • Registered Users, Registered Users 2 Posts: 3,484 ✭✭✭randombar


    That's weird, doesn't crash it for me? Is it something to do with my version of FF?? Strange!


  • Registered Users, Registered Users 2 Posts: 872 ✭✭✭grahamor


    it crashes FF for me too. Nothing appears in IE7 at all, just a grey box


  • Registered Users, Registered Users 2 Posts: 3,484 ✭✭✭randombar


    Balls it must be one of the erorrs in the javascript: Here it is anyways





    <script type="text/javascript" language="javascript" src="http://api.maptp.map24.com/ajax?appkey=FJX56c74b42a3080e5f0c661db0e14e7X13"></script&gt;
    <script type="text/javascript" language="javascript">

    function goMap24() {
    Map24.loadApi( ["core_api", "wrapper_api"] , map24ApiLoaded );
    }

    function map24ApiLoaded(){
    Map24.MapApplication.init( { NodeName: "largemap24" } );
    }


    function printResult( location ){
    var result = location.getStreet() + ", ";
    result += location.getCity() + ", ";
    result += location.getCounty() + ", ";
    result += location.getState() + ", ";
    result += location.getCountry();
    return result;


    }


    function reverseGeocode(lon, lat ){
    var geocoder = new Map24.GeocoderServiceStub();
    geocoder.reverseGeocode({ Longitude: lon, Latitude: lat, CallbackFunction: printResult });
    }

    //Callback function that is called when the client has received a response from the Web services.
    //The parameter contains the reverse geocoded address. The function reads the address data
    //and shows it in a list.

    "destination" = reverseGeocode( -8.74151, 51.7413 );


    var geocoder = null;
    var router = null;
    var routePoints = [];
    var routeID = null;

    function startRouting(){
    //Retrieve start and destination of the route from the input fields
    var startString = Map24.trim( $v('start') );
    var destinationString = Map24.trim( "destination" );

    //Check if the start and the destination form fields are empty.
    if( startString == "" ) { alert("destination"); return; }
    if( destinationString == "" ) { alert("Please enter destination address!"); return; }

    document.getElementById("button_calculate_route").disabled = true;

    //Create a geocoder stub
    var geocoder = new Map24.GeocoderServiceStub();
    //Geocode the start address of the route
    //Define the name of the callback function that is called when the result is available on the client.
    geocoder.geocode({
    SearchText: startString,
    MaxNoOfAlternatives: 1,
    CallbackFunction: setRouteEndPoint,
    CallbackParameters: {position: "start"}
    });

    //Geocode the destination address of the route.
    //Define the name of the callback function that is called when the result is available on the client.
    geocoder.geocode({
    SearchText: destinationString,
    MaxNoOfAlternatives: 1,
    CallbackFunction: setRouteEndPoint,
    CallbackParameters: {position: "destination"}
    });
    }

    //Callback function that is called when the geocoding result is available.
    //After both the start and the destination address is geocoded, this function calls the calculateRoute() function.
    //The geocoded address is stored at the first position in the locations array.
    function setRouteEndPoint(locations, params){
    //Access the geocoded address and add it to the routePoints array.
    routePoints[ params.position ] = locations[0];

    if( typeof routePoints["start"] != "undefined" && typeof routePoints["destination"] != "undefined")
    calculateRoute();
    }

    //Calculate the route.
    function calculateRoute() {
    router = new Map24.RoutingServiceStub();
    router.calculateRoute({
    Start: routePoints["start"],
    Destination: routePoints["destination"],
    CallbackFunction: displayRoute
    });
    routePoints = [];
    }

    //Callback function used to access the result of the route calculation.
    //This function is called after the client has received the result from the Routing Service.
    //The route parameter is of type Map24.WebServices.Route.
    function displayRoute( route ){

    //Remember the routeId. It is used to hide a route.
    routeID = route.RouteID;

    //Access the assumed time needed for traversing the route in hours
    var totalTime = ((route.TotalTime)/(60*60) ).toPrecision(3)
    //Access the total lenght of the route in kilometers
    var totalLength = (route.TotalLength/1000)
    //Create table with description of the route
    var div_content = "Total Time: " + totalTime + " h<br>" ;
    div_content += "Total Length: "+ totalLength +" km<br>";
    div_content += "<br>";

    //Iterate through the route segments and output the step-by-step textual description of the route
    for(var i = 0; i < route.Segments.length; i++){
    for(var j = 0; j < route.Segments.Descriptions.length; j++){
    //The route description contains tags for further evaluation. For example, the [M24_STREET] tag is used
    //to denote a street in the description. Add the following line of code to replace these tags by a blank:
    div_content += (i+1) + ". " + route.Segments.Descriptions[j].Text.replace(/(\[|\[\/)[0-9A-Z_]+\]/g, '' ) + "<br>";
    }
    }
    document.getElementById('route_description').innerHTML = div_content;

    document.getElementById("button_hide_route").disabled = false;
    document.getElementById("button_remove_route").disabled = false;
    }

    //Show route
    function showRoute(routeID) {
    router.showRoute({RouteId: routeID});
    document.getElementById("button_show_route").disabled = true;
    document.getElementById("button_hide_route").disabled = false;
    }

    //Hide route
    function hideRoute(routeID) {
    router.hideRoute({RouteId: routeID});
    document.getElementById("button_show_route").disabled = false;
    document.getElementById("button_hide_route").disabled = true;
    }

    //Remove route
    function removeRoute(routeID) {
    router.removeRoute({RouteId: routeID});

    document.getElementById("button_calculate_route").disabled = false;
    document.getElementById("button_show_route").disabled = true;
    document.getElementById("button_hide_route").disabled = true;
    document.getElementById("button_remove_route").disabled = true;
    }

    //Helper function.
    function $v( id ) {
    return (document.getElementById( id ).value != "undefined") ?
    document.getElementById( id ).value : "";
    }
    </script>




    The function's I am trying to edit are:

    function reverseGeocode(lon, lat )

    printResult( location )

    and use the result of printResult as the "destination" variable in the other functions?????


    Thanks for any help you can give me!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,011 ✭✭✭colm_c


    Download Firebug: https://addons.mozilla.org/en-US/firefox/addon/1843

    It's great for debugging javascript and also doing DOM inspection.


  • Registered Users, Registered Users 2 Posts: 3,484 ✭✭✭randombar


    Ya that seems like a class tool all right, definitely gonna have another look! Thanks!

    Doesn't really help my problem with the javascript though. Not really debugging it for me for some reason?


  • Registered Users, Registered Users 2 Posts: 3,484 ✭✭✭randombar


    Got it working (Kind of)

    http://www.ratemypub.ie/directions.php?pubid=245

    God bless the people of map24

    not working in IE???


Advertisement