InfoWindow from JSON data not displaying in Google Maps V3

My current project involves using PHP to generate a JSON file from data stored in MySQL. One of the goals I have is to display certain pieces of this data in an information window on Google Maps whenever I click on a marker.

Although I've managed to make all markers visible on the map, I keep encountering the following error message:

Uncaught ReferenceError: InfoWnd is not defined

I believe that there might be an issue with how I am setting up the info window, but despite trying out different methods, I always end up with the same error.

This is an outline of my JavaScript code so far:

** In order to initialize the map canvas:

<script type="text/javascript">
            var map;
    function initialize() {
                    var mapOptions = {
                      center: new google.maps.LatLng(48.476, -81.312),
                      zoom: 18,
                      mapTypeId: google.maps.MapTypeId.SATELLITE
                    };
                    map = new google.maps.Map(document.getElementById("map_canvas"),
                            mapOptions);
    }
    </script>
<body onload="initialize()">
    <div id="map_canvas" style="width=80%; height: 100%"></div>

** Additionally, creating markers and info windows:

<script type="text/javascript">
    var blueIcon = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
    var redIcon = "http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png";
    var greenIcon = "http://www.google.com/intl/en_us/mapfiles/ms/micons/green-dot.png";
    infoWnd = new google.maps.InfoWindow();

    $(document).ready(function() {
        $.ajax({
            url: 'http://localhost/testing/map_json.php',
            dataType: 'json',
            success: function (jsonData) {
                $.each(jsonData, function(key, data) {
                     var latLng = new google.maps.LatLng(data.lat, data.lng);

                     if ( data.R_1 === undefined ) {

                          if ( data.SysV >= 6.5 ) {
                               var marker = new google.maps.Marker({
                                   position: latLng,
                                   title: data.RTU_Addr,
                                   icon: blueIcon
                                });
                                setInfoWindow();
                           }
                           else {
                               var marker = new google.maps.Marker({
                                   position: latLng,
                                   title: data.RTU_Addr,
                                   icon: redIcon
                                });
                                setInfoWindow();
                           }
                      }

                      else {
                          if ( data.SysV >= 6.5 ) {
                              var marker = new google.maps.Marker({
                                  position: latLng,
                                  title: data.RTU_Addr,
                                  icon: greenIcon
                               });
                               setInfoWindow();
                           }
                           else {
                               var marker = new google.maps.Marker({
                                   position: latLng,
                                   title: data.RTU_Addr,
                                   icon: redIcon
                                });
                                setInfoWindow();
                            }

                        }
                        marker.setMap(map);

                        function setInfoWindow() {
                            google.maps.event.addListener(marker, 'click', function() {
                                infoWnd.setContent("hi");
                                InfoWnd.open(map, marker);
                             });
                         };
                     });    
                 }
             });
        });
    </script>

Does anyone have any suggestions on where I may have made a mistake?

Answer №1

There is a mistake with the usage of InfoWnd instead of infoWnd in the function called setInfoWindow().

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript Filter Function: filtering based on multiple conditions (either one can evaluate to true)

I seem to be missing something very simple here. I am working with an array of objects that contains various information. Depending on user interaction, I want to filter out certain objects; let arr = [ {'num': 1, 'name': 'joe&a ...

Automated scheduling tasks for Jersey Web applications

I have created a RESTful web service using Jersey in Java. It serves as a JSON service for scraped web data. Currently, I save my entire set of scraped data (A Set<Object>) to a file and deserialize it from disk when requested by the user. The web ap ...

Tips on transforming json data into nested Maps with Gson

I have a custom Java class MyModel.java: public class MyModel { String name; int age; Details details; } In Details.java I have: public class Details { Info info1; Info info2; } In Info1.java and Info2.java, both have a common field called data ...

Warning: The class name hydration discrepancy between server and client (Caution: Property `className` does not correspond between the Server and the Client)

Trying to figure out if my problem is a stubborn bug, a support issue, or just a configuration mismatch has been quite the journey. I've spent so much time on this, not exactly thrilled to be reaching out for help. After searching for 3 days and only ...

Differences between Typescript Import and JavaScript import

/module/c.js, attempting to export name and age. export const name = 'string1'; export const age = 43; In b.ts, I'm trying to import the variables name and age from this .ts file import { name, age } from "./module/c"; console.log(name, ...

The execution of jQuery Ajax requests with "when" is encountering issues

My goal is to initiate 8 ajax GET requests N number of times, and this is the code I have written: var me = this; urls.forEach(function(requests){ $.when(requests.map(function(request){ return $.ajax(request) })).done(function(data){ me.result ...

Display list items in HTML based on the length of an array

In my backend, I have a user-defined array of cars. If the user selects 3 cars, the array will contain 3 elements. I would like to display specific details of the cars in HTML elements within a list. The array is based on JavaScript. Here is an example of ...

Firefox's keyup event

Is it possible to detect a keypress using the jQuery keyup function, as I am facing an issue where it works in Chrome, Edge, IE, and Opera but not in Firefox. $(".textfield").contents().keyup(function(evnt) { document.getElementById("btn_save").style. ...

Tips for importing font files from the node_module directory (specifically otf files)

We cannot seem to retrieve the fonts file from the node module and are encountering this error message. Can't find 'assets/fonts/roman.woff2' in 'C:\Projects\GIT2\newbusinessapp\projects\newbusinessapp\src ...

Displaying a div after a successful form submission using Jquery

I created two popup windows. One is used to ask the user whether they want to submit the form, and if they click 'yes', the form is submitted. The issue I encountered is that the other popup window should be shown after the form is successfully s ...

What could be the reason for the component failing to update even after modifying the object's properties?

I have come across some related threads on Stack Overflow, but they only briefly mention using the spread operator. But why should we use it? In the code below, I am trying to update the firstName property of the user object, which is a state, when clicki ...

I've come across this ajax url that seems promising, but I keep getting a GET 404 (Not Found)

I am attempting to validate using ajax and php. This is the code I have for my ajax: function PrintRecibopapel() { recibo = document.getElementById("txtCod").value; if(recibo == "") { alert("You must save the receipt before pr ...

What could be the reason behind the disruption in this JavaScript associative array?

I'm facing an issue with my associative array, which I have confirmed through console.log to be initially: this.RegionsChecked = {"US":true,"APAC":true,"Canada":true,"France":true,"Germany":true,"India":true,"Japan":true,"LATAM":true,"MEA":true,"UK": ...

What could be causing the malfunction of the Facebook iframe like button?

Even though it functions offline, there seems to be an issue with its performance online. Here is the code that was used: <iframe src="http://www.facebook.com/plugins/like.php?app_id=125925834166578&amp;href=http%3A%2F%2Fwww.facebook.com%2FBaradei. ...

Having trouble locating the module 'monaco-editor/esm/vs/editor/editor.worker' while using create react app

I am currently facing some challenges running react-monaco-editor in my project despite following the documentation and making necessary adjustments to my files. Below is a snippet of my package.json file: { "name": "chatbot_compiler", "version": "0. ...

MongoDB error codes and their associated HTTP status codes are important for developers to understand

When a new user attempts to sign up with an existing user account, MongoDb triggers a 11000 error code In Express, handling this scenario can be done as follows: async function signup(req, res, next){ try{ // perform some actions }catch(err){ i ...

What is the best way to convert a List of objects to JSON using a dynamic variable?

I have a need to serialize a list of objects in a specific way: Imagine I have the following C# class: public class Test { public string Key; public string Value; } List<Test> tests; When I serialize this list (return Json(tests.ToArray()) ...

What are the steps to use grunt for running a node.js application?

Directory Structure: myapp --public(directory) //contains files related to public (AngularJS, CSS, etc) --server(directory) //contains files related to server --server.js Code server.js //located at root directory ---------------------- ... var app = ...

The PHP script encounters an Ajax request and returns a null response

My current challenge involves sending data from the browser's local storage to PHP using AJAX. When I test the API in Postman by inputting this data (POST): [ { "product-id": "32", "product-name": "Reese Stevenson&qu ...

What could be the reason for my inability to retrieve req.user.username with passport.js?

I recently started using passport.js for authentication and I'm encountering an issue. When I log in via Google, the only information available to me through req.user is the user id. I have provided my passport setup code, along with the routes, hopin ...