question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

adding custom icon = google' is not defined

See original GitHub issue

I cant set a new custom icon. I’m not so familier with HOC and how to use it. I tried to call <MapContainer /> and <GoogleApiWrapper /> but both gave me same error. everything else works fine if i remove the custom icons.

what did i miss?!

This is the error i get!

Line 46:  'google' is not defined  no-undef
  Line 47:  'google' is not defined  no-undef

Here is my code!

import React, { Component } from 'react';
import {Map, InfoWindow, Marker, GoogleApiWrapper} from 'google-maps-react';

export class MapContainer extends Component {
    constructor(props) {
    super(props);
    this.onMarkerClick = this.onMarkerClick.bind(this);
    this.state = {
      showingInfoWindow: false,
      activeMarker: {},
      selectedPlace: {},
    }
  }
  onMarkerClick(props, marker, e) {
    this.setState({
      selectedPlace: props,
      activeMarker: marker,
      showingInfoWindow: true
});
  }
render() {
    return (
      <Map google={this.props.google} zoom={14}>
        <Marker onClick={this.onMarkerClick}
              icon={{
            url: "/img/icon.svg",
            anchor: new google.maps.Point(32,32),
            scaledSize: new google.maps.Size(64,64)
            }}
          name={'Current location'} />
         <InfoWindow
          marker={this.state.activeMarker}
          visible={this.state.showingInfoWindow}>
            <div>
              <h1>{this.state.selectedPlace.name}</h1>
            </div>
        </InfoWindow>
      </Map>
    );
  }
}
export default GoogleApiWrapper({
  apiKey: ('A***********')
})(MapContainer)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
fl0r3kcommented, Mar 30, 2018

Found it!

In your render method add const {google} = this.props;

It should start working. If you don’t see you marker then try pointing image that is visible in internet.

1reaction
oscarmyepescommented, Jan 30, 2019

If you want to have a custom Marker with text, styles, etc, this is what worked for me:

<Marker
   ... 
    icon={{
      url: 'data:image/svg+xml;utf8,<svg ... > ... </svg>'
    }}
>

The last part <svg … > … </svg> could be a function that return an svg and you can pass in properties.

 icon={{
    url: 'data:image/svg+xml;utf8,getCustomSvg(price, rate)'
    }}

Example

export default (price, rate) => `
<svg xmlns="http://www.w3.org/2000/svg" width="65" height="20" viewBox="0 0 65 20">
<g fill-rule="evenodd">    
    <text font-size="8.276" font-weight="bold">
        <tspan x="4" y="13">${price}</tspan>
    </text>    
    <text font-size="8.276" font-weight="bold">
        <tspan x=".37" y="8">${rate}</tspan>
    </text>
</g>
</svg>`;

Result:

image

Reference: https://css-tricks.com/lodge/svg/09-svg-data-uris/

Read more comments on GitHub >

github_iconTop Results From Across the Web

map-icons.js google is not defined - Stack Overflow
I'm sure. it points out "google.maps.marker" at map-icons.js so i think it's because of inheritence. – pinyil. Jul 17, 2017 ...
Read more >
Custom Symbols (Polyline) | Maps JavaScript API
This example adds a custom symbol to a polyline. ... Define the custom symbols. ... Create the polyline and add the symbols via...
Read more >
Add Custom Markers with the Google Maps JavaScript API
In this article, I will go through how to create a map, adding markers, how to add customize icons for markers, and how...
Read more >
Changing the Marker Icon | GEOG 863: Mashups
When assigning a custom icon to a Marker, there are two optional ... if one is not defined, so it is not really...
Read more >
Google Maps JavaScript API Tutorial - YouTube
We will implement a map with some custom markers, info window, event listeners and we will optimize the code so that we can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found