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 7160795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:27:26+00:00 2026-05-28T13:27:26+00:00

I use google maps API to display markers on a map. Each marker points

  • 0

I use google maps API to display markers on a map.

Each marker points to a shop on the map.

My problem is with creating the event handler for each mark, which will display the tooltip with information about the shop when the given mark will be clicked.

I use the text input to let the user type the city, and with jquery I handle the click event on the nearby submit button. Then I send the query to the php site, get following object back:

d: Object
error: false
lat: "52.3744440000"
lng: "9.7386110000"
shop: Array[2]
0: Object
address: "Addressstreet 12"
lat: "52.3761209000"
lng: "9.7387242000"
name: "Shop 1"
tel: "1234"
__proto__: Object
1: Object
length: 2
etc.

Now I use the lat and lng values which are coordinates of the city to center the map.
Then I send the shop array to the paintShops(shops) method:

function paintShops(shops){
for (var i = 0; i < shops.length; i++){
kl = shops[i];
var ka = parseFloat(kl.lat);
var kb = parseFloat(kl.lng);
tel = kl.tel;
address = kl.address;
var son = new google.maps.Marker({
position: new google.maps.LatLng(ka, kb),
map: map,
title: kl.name,
clickable: true
});
google.maps.event.addListener(son, 'click', function(son, tel, address) {
displayShopTooltip(son, tel, address);
}

My problem is in the last line of the above snippet: when I click on the mark, the parameters tel and address of the displayShopTooltip are undefined.
I’d like to know what to do to do not have this problem, or alternatively another approach.
Thanks in advance.

  • 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-05-28T13:27:27+00:00Added an answer on May 28, 2026 at 1:27 pm

    The problem you have is that by declaring tel and address within the listener you are setting them to undefined within the event handler callback (as there is no mechanism for passing in arbitrary parameters). The solution is to make sure the handler is within the same scope as (i.e. wrapped inside a function with) the marker. I’d recommend reading up about scope in javascript as there were one or two other errors you made (e.g. not properly declaring variables) – scope in javascript is handled very differently to other programming languages and takes a bit of getting used to.

    function paintShops(shops){
      for (var i = 0; i < shops.length; i++){
        makeMarker(shops[i]);
      }
    
      function makeMarker(kl) {
        var ka = parseFloat(kl.lat);
        var kb = parseFloat(kl.lng);
        var tel = kl.tel;
        var address = kl.address;
        var son = new google.maps.Marker({
           position: new google.maps.LatLng(ka, kb),
           map: map,
           title: kl.name,
           clickable: true
        });
         google.maps.event.addListener(son, 'click', function(son) {
           displayShopTooltip(son, tel, address);
         }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to use Google maps static API to display a map with a
I'm using Google Maps API to display a map and some markers on it.
I'm experiencing a problem while trying to use google maps api v3 (with marker
My Google maps are configured to display blue location markers. My maps use the
I use the google maps family API. I want to display a car on
So my site uses the Google Maps API to display a map of the
I had the following HTML page rendering to use the Google Maps API. This
I am using GWT for google map application. I use Google's gwt-maps.jar for mapping
I need to display multiple markers on a map, each with their own infowindow.
I'm using the Google maps API (v2) to display a country overlay over a

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.