SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Issue with Map24 Ajax API

    Hi There,

    This might end up being a lengthy post - sorry about that.

    I am working on a site that is using the Map 24 Ajax API. And I have run into an issue that I don't understand. I can't access their forum and it says I am not allowed to post support issues anyway... so here goes:

    Let me try to explain as simply as possible.

    I have the map up and running and I can center the map on a given coordinate by using the function:

    centerMapOnGivenCoordinate(150.6417, 2500.7654);

    The function looks like this:

    Code:
    function centerMapOnGivenCoordinate(long, lat){
      M24.centerOnLonLat( long, lat, 5000 );			 
    }
    The function works great when I call it from a button like this:

    HTML Code:
    <input type="button" value="Center Map On a Given Coordinate" onclick="centerMapOnGivenCoordinate(150.6417, 2500.7654)">
    But - I would REALLY like to call the function from within another function that is called by code generated by JavaScript.

    OK - I know that sounds confusing but stay with me.

    I have three <select> boxes: Country, Area, Town.

    Country is flat HTML (generated by PHP)

    Area and town are generated by Ajax depending on what Country/Area is selected.

    When a town is selected then I would like to execute my centerMapOnGivenCoordinate() function.

    Well actually - I want to execute the following function:

    Code:
    function sendCordinatesToMap(link_id) {
      var longitude = getLongitude(link_id, "type=r");
      var latitude = getLatitude(link_id, "type=r");
              
      alert("Long/LAT: "+longitude+", "+latitude);
    					
      M24.centerOnLonLat( longitude, latitude, 5000 );	
    }
    Which I do successfully with this code:

    HTML Code:
    <select name="tid" class="searchSelect" onChange="sendCordinatesToMap(document.searchForm.tid.value)">
    The two functions getLongitude() and getLatitude() sucessfully returns two valid coordinates - which is confirmed by the alert just below them, but the M24.centerOnLonLat( longitude, latitude, 5000 ); call does NOT work and returns:

    uncaught exception: M24.centerOnLonLat(): [-1] Invalid coordinates (lon, lat) passed. {-419.9004}

    the -419.9004 is one of the coordinates (longitude)

    I know that the coordinates are valid as I have tried them with the button mentioned above.

    I am quite new to Ajax and JavaScript and I have a feeling that it might have to do with "loss of scope" or something like that - but I haven't got a clue.

    Please PM me if you would like a link to the site in question.

    Any help will be MUCH appreciated!
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got support back from Map24 and they told me to use the advanced function instead of the simple:

    function centerMapOnGivenCoordinate(lon, lat, distance){
    var mrcContainer = new Map24.Webservices.Request.MapletRemoteControl();
    mrcContainer.push(
    new Map24.Webservices.MRC.SetMapView({
    Coordinates: new Map24.Coordinate( lon, lat ),
    ClippingWidth: new Map24.Webservices.ClippingWidth(
    { MinimumWidth: distance }
    )
    })
    );
    map.Webservices.sendRequest( mrcContainer );
    }
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •