LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-18-2016, 07:10 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Rep: Reputation: 12
Google Maps API - google Map won't load


Am feeding lat and lng variables to google map from dynamic select/options.
In alert() I am seeing that the correct lat and lng are being produced but when passed to mapOptions map doesn't load. Thanks in advance for help.

R

Here is my code:

Code:
 <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Google Maps API getting Lat and Long with Geocoding</title>
        
       <link rel="stylesheet " type="text/css" href="css/loadList.css" />
       <link rel="stylesheet " type="text/css" href="css/gps.css" /> 
       
        <script src="../jquery/jquery-2.1.4.js"></script>
        <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
        <script type="text/javascript" src="../jquery/getHtmlParams.js"></script>     
     
    <script type="text/javascript">
          var name;
          var index;
          var address;
          var lat;
          var lng;
          
    $(document).ready(function(){

    loadlist($('#latlng').get(0),                   /*the 'select' object*/
     'getMarkers.php?getlist=latlng', 'name');
         
    function loadlist(selobj, url, nameattr) {

        $(selobj).empty();
        $.getJSON(url, {}, function(data) {

            $.each(data, function(i,obj) {          
                $(selobj).append($('<option></option>').val(obj[nameattr]).html(obj[nameattr]));
            }); //each
        
      $("#latlng").change(function(){
     
          name=$(this).val();
          index=this .selectedIndex;
          address=data[index]['address'];
          lat=data[index]['lat'];
          lng=data[index]['lng'];
      
          mapIt(name, address, lat, lng);              // off to load google maps
               
    }) // latlng
               
    }); // getJSON 
    } // loadlist
    }); // doc ready

    </script>

    </head>

    <body>

    <div id="loadListWrapper">
     
    <label id="markerLbl" >Select Marker For:</label><br>
    <select name='latlng' id='latlng' size='5'></select>

    </div> <!-- loadListWrap -->

    <!-- ====================================================== -->

    <script type="text/javascript">
       
        function mapIt(a, b, c, d) {              // c & d are lat an lng
        var latlng=c+", "+d;
       
    alert(latlng);        // shows lat & lng

    var mapOptions={
    zoom:8,
    center: new google.maps.LatLng(latlng),
    mapTypeId: google.maps.MapTypeId.ROADMAP

    }; // mapOptions

    var map=new google.maps.Map($("#map").get(0), mapOptions);    // doesn't load
               
    }; // mapIt

    </script>

    <!-- ============================================================= -->

    <div id="map" >  <!-- where map goes -->

    </div>
     
    </body>
    </html>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Top 5: Open stickers, 3 alternatives to Google Maps API, and more LXer Syndicated Linux News 0 11-20-2015 06:32 PM
LXer: Celebrate GIS Day 2015 with 3 open source alternatives to Google Maps API LXer Syndicated Linux News 0 11-18-2015 12:41 PM
LXer: Show Photos on Google Earth and Google Maps with*digiKam LXer Syndicated Linux News 0 10-12-2011 08:20 PM
[SOLVED] Google Maps works well in Google Chrome but not in Chromium... Robert.Thompson Slackware 1 04-13-2011 02:47 AM
LXer: Google Maps and Google Earth KML overlays LXer Syndicated Linux News 0 10-29-2008 04:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration