Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error :this.setValues is not a function in js code use google map api

here is code of java script :

<script>
        function initMap() {
            var lat = 10;
            var lng = 10;
            var propertyCenter = {lat: 10, lng: 10};
            var propertymap = {
                center: new google.maps.LatLng(lat, lng),
                zoom: 7,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(document.getElementById("propmap"), propertymap);

            var marker = google.maps.Marker({
                position: propertyCenter

            });
            marker.setMap(map);

        }
        google.maps.event.addDomListener(window, 'load', initMap);

    </script>

I am getting following error on console :

js?key=my_key&callback=initMap:65 Uncaught TypeError: this.setValues is not a function

like image 392
Prabhjot Singh Avatar asked Apr 13 '16 12:04

Prabhjot Singh


People also ask

Why is my Google Maps API not working?

There are a several reasons why your google maps may not be working, the most common issue being no Google Map API key set or set incorrectly. To use the Google Maps JavaScript API, you must register your app project on the Google Cloud Platform Console and get a Google API key which you can add to your app.

How to Check Google map API key is working or not?

Go to the Credentials section, which can be accessed from the left side bar under Google Maps Platform > Credentials. Check that the API key you currently use on your website is listed. If that's not the case, switch to a different project, and check the credentials there.

How to test Google API key?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key. Click Close.


1 Answers

Take a look at Map Markers Not Displaying (JavaScript/Google Maps API V3)

Try changing

var marker = google.maps.Marker

to

var marker = new google.maps.Marker

Adding new should fix your issue

This also applies to the library load-google-maps-api for those using webpack.

loadGoogleMapsAPI().then((googleMaps) => {
  new googleMaps.Map(element, {options})
}).catch((err) => {
    console.error(err)
})
like image 112
drt Avatar answered Sep 17 '22 18:09

drt