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

  • SEARCH
  • Home
  • 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 8228567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:30:04+00:00 2026-06-07T16:30:04+00:00

How can I clean this so that the code handles multiple listings better? I

  • 0

How can I clean this so that the code handles multiple listings better? I have seen some code examples that pull the marker info from an array, but I can’t seem to get it to work.

The markers need to have “icon:”, “url:” and “title:” attributes. The “icon:” so I can change each markers appearance, the “url:” to point through to the page dedicated to each marker and the “title” just to add the markers name on hover.

I also need the array in the script as I am not gathering it from a database or anything like that.

I am pretty green when it comes to javascript and google maps api, any help would be greatly appreciated.

function createMap(lat, lng, zoomVal) {
 var mapOptions = { center: new google.maps.LatLng(lat, lng),    
 zoom: zoomVal,   
 scrollwheel: false,  
 mapTypeId: google.maps.MapTypeId.ROADMAP 
}; 
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);


var myLatlnglow = new google.maps.LatLng(23.654332,-79.387867);

var markerlow1 = new google.maps.Marker({
    position: myLatlnglow,
    icon: 'images/map-dot.png',
    map: map,
    url: '#',
    title: 'Name'
});
google.maps.event.addListener(markerlow1, 'click', function() {
window.location.href = markerlow1.url;
});


var myLatlnglow = new google.maps.LatLng(23.688458,-79.300619);

var markerlow = new google.maps.Marker({
    position: myLatlnglow,
    icon: 'images/map-dot.png',
    map: map,
    url: '#',
    title: 'Name'
});
google.maps.event.addListener(markerlow, 'click', function() {
window.location.href = markerlow.url;
});


}

var map;
function initialize() { 
 createMap(23.668493, -29.410812,12);
  if(navigator.geolocation) {  
  success = function(position) {    
 createMap(position.coords.latitude, position.coords.longitude,13);  
};   
error = function() {
 createMap(23.648493, -29.410812,12); 
}    
 navigator.geolocation.getCurrentPosition(success, error);  
} 
}
  • 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-07T16:30:06+00:00Added an answer on June 7, 2026 at 4:30 pm

    If I were you I would make an object of objects for the sake of readability. If you must have efficiency, and want to save space and typing, replace the object with an array and address the data by index (0,1,2…)

    Here’s a demo

        // inside function createMap(...)
          ...
        markerData = {
            bing: {
                lat: 23.654332,
                lng: -79.387867,
                icon: "http://labs.google.com/ridefinder/images/mm_20_red.png",
                url: "http://www.bing.com/",
                title: "some search engine"
            },
            yahoo: {
                lat: 23.688458,
                lng: -79.300619,
                icon: "http://labs.google.com/ridefinder/images/mm_20_blue.png",
                url: "http://www.yahoo.com/",
                title: "Great free games"
            }
        };
    
        for (markerId in markerData) {
            markers[markerId] = createMarker(markerData[markerId]);
        }
    
        markers['bing'].setTitle("new title");
    }
    
    function createMarker(data) {
        var myLatLng = new google.maps.LatLng(data.lat, data.lng);
    
        var marker = new google.maps.Marker({
            position: myLatLng,
            icon: data.icon,
            map: map,
            title: data.title
        });
        google.maps.event.addListener(marker, 'click', function() {
            window.location.href = data.url;
        });
    
        return marker;
    }
    

    It should also help later to save the references to the created markers, I’m using the global object markers and the same IDs.

    var map;
    var markers = {};
    

    If you later need to change a marker property it is accessible through markers.

       markers['bing'].setTitle("new title");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have PHP code that handles the logic for this because I do
How can I clean this up using rails 3 features? I have a post
I'm debugging some Java code that uses Apache POI to pull data out of
I'm developing some lower end code in my system that uses multiple child classes
I have this problem that I can't seem to find a solution for... I
Hoping that someone can help clear up this very annoying situation I find myself
Hoping someone can clear this up for me. Let's say I have 2 globals:
I can't see a clear mistake in this code. Instead of validating my fields,
the problem i have is that i have multiple nested master pages: level 1
This questions is related to java exceptions, why are there some cases that when

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.