How to use a react component for showing Google Maps InfoWindow

General Tech Bugs & Fixes 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

i have my code as follows, i am not using any external libraries inside my react app

import React, { Component } from "react";
import MarkerInfo from "./MarkerInfo";
import { render } from "react-dom";

class Map extends Component {
componentDidMount() {
    this.renderMap();
}

renderMarkerInfo = () => {
    return (
    <div id="markerinfo">
        <h1>THis is info markerh1>
    div>
    );
};

renderMap = () => {
    loadScript(
    "https://maps.googleapis.com/maps/api/js?key=AIzaSyC0Ihrl2V6nAHzYMxQc_CeJEtd9sW5AA6Q&callback=initMap"
    );
    window.initMap = this.initMap;
};

initMap = () => {
    var uluru = { lat: -25.363, lng: 131.044 };
    var map = new window.google.maps.Map(document.getElementById("map"), {
    zoom: 4,
    center: uluru
    });

    var contentString =
    '
content">' + '
' + "
"
+ '

Uluru

'
+ '
' + "

Uluru, also referred to as Ayers Rock, is a large " + "sandstone rock formation in the southern part of the " + "Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) " + "south west of the nearest large town, Alice Springs; 450&#160;km " + "(280&#160;mi) by road. Kata Tjuta and Uluru are the two major " + "features of the Uluru - Kata Tjuta National Park. Uluru is " + "sacred to the Pitjantjatjara and Yankunytjatjara, the " + "Aboriginal people of the area. It has many springs, waterholes, " + "rock caves and ancient paintings. Uluru is listed as a World " + "Heritage Site.

"
+ '

Attribution: Uluru, ' + "https://en.wikipedia.org/w/index.php?title=Uluru " + "(last visited June 22, 2009).

"
+ "
"
+ "
"
; var infowindow = new window.google.maps.InfoWindow({ content: contentString }); var marker = new window.google.maps.Marker({ position: uluru, map: map, title: "Uluru (Ayers Rock)" }); marker.addListener("click", function() { infowindow.open(map, marker); }); }; render() { return (
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.