adding custom icon = google' is not defined
See original GitHub issueI 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:
- Created 5 years ago
- Reactions:4
- Comments:8 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
If you want to have a custom Marker with text, styles, etc, this is what worked for me:
The last part <svg … > … </svg> could be a function that return an svg and you can pass in properties.
Example
Result:
Reference: https://css-tricks.com/lodge/svg/09-svg-data-uris/