1

I am using the gpxviewer on my website to show .gpx files in google maps. It works great from the normal domain, but not when using dynamically created subdomains. As the script says, and after searching stackoverflow and google, I am pretty sure this is caused by the same origin policy. After searching a bit further, I think I need to solve this issue using jsonp (e.g. jsonp in layman terms). However, my javascript/jquery sucks, so am not sure if jsonp will work, and after reading through some jsonp tutorials, I still don't have a clue how to implement jsonp in order to get the gpxviewer to work on my subdomains. My code:

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'></script>
<script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=false'></script>
<script src='absolute path to loadgpx.js' type='text/javascript'></script>
<script type='text/javascript'>
    function loadGPXFileIntoGoogleMap(map, filename) {
        $.ajax({
            url: filename,
            dataType: 'xml',
            success: function (data) {
                var parser = new GPXParser(data, map);
                parser.setTrackColour('#ff0000'); // Set the track line colour
                parser.setTrackWidth(2); // Set the track line width
                parser.setMinTrackPointDelta(0.001); // Set the minimum distance between track points
                parser.centerAndZoom(data);
                parser.addTrackpointsToMap(); // Add the trackpoints
                parser.addWaypointsToMap(); // Add the waypoints
            }
        });
    }
    $(document).ready(function () {
        var mapOptions = {
            zoom: 8,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById('map'), mapOptions);
        loadGPXFileIntoGoogleMap(map, 'absolute path to .gpx file');
    });
</script>
<div id='map' style='width: 553px; height: 280px'></div>

Any help would be appreciated.

Community
  • 1
  • 1
jc100
  • 11
  • 2
  • You have to use the URL to a JSONP file instead of a GPX file (and tell jQuery that you want to use JSONP instead of XML). – Quentin Nov 27 '13 at 11:07

0 Answers0