Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

jquery - Loading googlemaps on page load

Hi iam trying to load googlemaps when the new page is loaded ..but itz not working below is my code

  <script type="text/javascript">

    var query = location.href.substring((location.href.indexOf('?')+1), location.href.length);
    if(location.href.indexOf('?') < 0) query = '';
    querysplit = query.split('&');
    query = new Array();

    for(var i = 0; i < querysplit.length; i++){
    var namevalue = querysplit[i].split('=');
    namevalue[1] = namevalue[1].replace(/+/g, ' ');
    query[namevalue[0]] = unescape(namevalue[1]);
    }
    window.onload = function(lat,lng){
    // Do stuff with query string data here.
alert(query['latitute']);
    var map;
    //code write to load map on right side
        var myLatlng = new google.maps.LatLng(lat,lng);
        map = new google.maps.Map(document.getElementById('map'), {
                        mapTypeId: google.maps.MapTypeId.ROADMAP,
                        center: myLatlng,
                        zoom: 10});
    }
    </script>

my goal is when i click link on firstpage the second page should load with the map taking the latlng from firstpage which are hardcoded..the alert statement is wrking but not the map load..trying to implement it in jquery or js..Any help is appreciated

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How did you receive lat and lng values? Have you tried show alert with this variables?

Also, if your first alert works, try this:

window.onload = function() {
    var lat = parseFloat(query['latitute']);
    var lng = parseFloat(query['longitute']);
    var map;
    var myLatlng = new google.maps.LatLng(lat, lng);

    map = new google.maps.Map(document.getElementById('map'),
        {
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            center: myLatlng,
            zoom: 10
        }
    );
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...