8

I'm getting this error all of a sudden when trying to add markers to a map in the CP:

Uncaught TypeError: this.lat is not a function

I've previously followed all of the advice on devot-ee about using a previous version of the Google Maps API, but this has now happened despite doing that.

Any advice on how to work around this?

0

2 Answers 2

20

The following fix works for me. The project in which I'm using this fieldtype does not require the use of most of the product's more advanced features so I can't guarantee that it fixes everything. Nor can I guarantee that it won't break something else. But hey, it's a start :-)

Open up /themes/third_party/gmap/javascript/gmap_field.js and search for "var updateValues". (The line number will vary depending on your addon version.) Modify the code as follows:

// @HACK VMG 2016-05-26
// Fixes "this.lat is not a function" error caused by
// the response object containing float values for lat
// and lng instead of a LatLng object.
$.each(response.markers.results, function(i, result) {
    response.markers.results[i].geometry.location = new google.maps.LatLng(result.geometry.location.lat, result.geometry.location.lng);
        });
$.each(response.waypoints.results, function(i, result) {
    response.waypoints.results[i].geometry.location = new google.maps.LatLng(result.geometry.location.lat, result.geometry.location.lng);
});
$.each(response.regions.results, function(i, result) {
    response.regions.results[i].geometry.location = new google.maps.LatLng(result.geometry.location.lat, result.geometry.location.lng);
});
var updateValues = [
    JSON.stringify(response.markers.results),
    JSON.stringify(response.waypoints.results),
    JSON.stringify(response.regions.results)
];

Hopefully that helps others of you who are facing the same problem.

4
  • Life saver! This worked for me. Commented May 26, 2016 at 22:06
  • This worked great for me on Google Maps for EE 3.3.8. Thanks Mr Wilson! :-)
    – Stephen
    Commented May 27, 2016 at 10:05
  • Nice one. This coupled with the fix below (it must be v3.22) worked for me.
    – liamcrean
    Commented Aug 17, 2016 at 9:56
  • Using the various fixes already mentioned the individual entries are working, but I still can't get the Importer to run correctly (whether it's 10 or 1000's of entries). The importer / geocoder still shows the error "this.lat is not a function"?
    – christiaan
    Commented May 15, 2017 at 6:15
1

You may have already tried this. This fix worked for me a while ago (I just checked - and GMAPS is still working fine on the site this fix was applied to).

Around line 180 in this file: system/expressionengine/thirdparty/gmap/ft.gmap.php

CHANGE THIS:

$this->EE->theme_loader->javascript('https://maps.google.com/maps/api/js?sensor=true');

TO THIS:

$this->EE->theme_loader->javascript('https://maps.google.com/maps/api/js?v=3.22&sensor=true');

7
  • Thanks Jules, yes, this change was already in place prior to the problem appearing. Commented May 26, 2016 at 1:31
  • I've also noticed this same issue happening in the last day or so on all the sites I have that use Google Maps for EE. I was also using the previous patch that was listed on Devot-ee: devot-ee.com/add-ons/support/google-maps/viewthread/15475
    – Stephen
    Commented May 26, 2016 at 10:40
  • I was just going to post that I did the same fix, but when checking the site now I see that this error is back. I also get this warning in my console "Google Maps API warning: RetiredVersion developers.google.com/maps/documentation/javascript/…" Commented May 26, 2016 at 17:06
  • Hello, Solutions explain above are works in past. None of this is working now. Do any one have some solution ? I have gmap 3.3.9 Commented Oct 6, 2016 at 10:43
  • It's best to change the line above to $this->EE->theme_loader->javascript('maps.google.com/maps/api/js?v=3&sensor=true');. This ensures that you're using the latest of API V3. I think v=3.24 and below have now been retired. Commented Nov 15, 2016 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.