Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9121727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:55:39+00:00 2026-06-17T05:55:39+00:00

Hello :) Please bear with me, I’m not a coder but I’m trying to

  • 0

Hello 🙂 Please bear with me, I’m not a coder but I’m trying to learn by doing. This is the page I’m working on currently; http://www.websu.it/devnw/dev/contact.html.
I’ve currently set up a map using the Google Maps API, using the following javascript:

    function initialize() {

          var mapOptions = {
          zoom: 5,
          center: new google.maps.LatLng(48.160, -6.832),
          disableDefaultUI: true,
          mapTypeId: google.maps.MapTypeId.ROADMAP
          };

         map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
             setMarkers(map, cities);
              }


 var cities = [
   ['Groningen', 53.216723950863425, 6.560211181640625, 4],
   ['San Francisco', 34.01131647557699, -118.25599389648437, 5],
   ['New York City', 40.7143528, -74.0059731, 3],
   ['Amsterdam', 52.3702157, 4.8951679, 2],
   ['Maroubra Beach', -33.950198, 151.259302, 1]
 ];

 function setMarkers(map, locations) {

   for (var i = 0; i < locations.length; i++) {
     var city = locations[i];
     var myLatLng = new google.maps.LatLng(city[1], city[2]);
     var marker = new google.maps.Marker({
         position: myLatLng,
         map: map,
         title: city[0],
         zIndex: city[3]
     });
   }
 }

 This continues below...

And then I created a list where every li element, when clicked upon, results in a panning of the map to one of these markers.

I’ve added the following code and it works very well. But it means that I have to add the longitudes/latitudes for every city in the above code array of “cities”, as well as in the code below for the var laLatLng. How can I get the lat’s and lon’s more easily in the panning script below?

      $(document).ready(function() {
      initialize();

      $("#contacts").on("click", "#sanfransisco", function() {
          var laLatLng = new google.maps.LatLng(34.01131647557699, -118.25599389648437);
          map.panTo(laLatLng);
          map.setZoom(5);
       });
      $("#contacts").on("click", "#groningen", function() {
          var laLatLng = new google.maps.LatLng(53.216723950863425, 6.560211181640625);
          map.panTo(laLatLng);
          map.setZoom(6);
      });
      $("#contacts").on("click", "#nyc", function() {
          var laLatLng = new google.maps.LatLng(40.7143528, -74.0059731);
          map.panTo(laLatLng);
          map.setZoom(6);
      });
      $("#contacts").on("click", "#losangeles", function() {
          var laLatLng = new google.maps.LatLng(52.3702157, 4.8951679);
          map.panTo(laLatLng);
          map.setZoom(6);
      });
  });

I hope someone can explain to me how to get the variables from cities into clickable list javascript. Thanks a lot, I deeply appreciate your response!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:55:40+00:00Added an answer on June 17, 2026 at 5:55 am

    If you convert the cities array to an object like:

    var cities = {
      'Groningen':  [ 53.216723950863425, 6.560211181640625, 4],
       'San Francisco': [ 34.01131647557699, -118.25599389648437, 5],
       'New York City': [ 40.7143528, -74.0059731, 3]
    
    };
    

    And add a data- attribute with matching city name along with a common class name to each of the links:

    /* not sure what html looks like , using pseudo "tagName"*/
    <tagName class="map_link" data-city="Groningen">Groningen</tagName>
    

    You can create one handler for the whole class:

    $("#contacts").on("click", ".map_link", function() {
              /* "this" within handler is the actual element clciked*/
    
              /* find correct array from "cities" object */
             var data=cities[ $(this).data('city') ]; /* returns array[ 53.21, 6.56, 4]*/
              var laLatLng = new google.maps.LatLng( data[0],  data[1]);
              map.panTo(laLatLng);
              map.setZoom( data[2]);
           });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello friends I have tried many times but I am not successful than please
Hello everyone please guide whats wrong with this code that image is not visible
Please refer to my page http://vault-x.com/v3/contact.html Contact me via email: hello[at]vault-x.com Follow Vault-X on
this is my first question so please bear with me! Im trying to write
I am trying to learn Java now and this is the hello world program
SOLVED - Please seen Darren's response for a working resolution to this issue. Hello,
Hello guys can you please help me with this problem. When a simple image
I have problem in displaying drop-down menu. Please, see the example on: http://staging.gwynconsulting.com/rif/hello-world-2/ When
I'm kind of new to this so please bear with me... Let's say I
Hello People please find my code below as you can see iam trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.