Gmaps.js stopped working

♀尐吖头ヾ 提交于 2019-12-02 08:51:18

Look at your code that handles the click event for each of your markers:

map.setCenter( e.position.k, e.position.D );

The setCenter() method in gmaps takes latitude and longitude arguments. Do k and D look like sensible names for these? :-)

I suspect that you found these properties by looking around in the developer tools while developing your code, is that right? Set a breakpoint on that line of code and take another look when you get there.

Yikes, there are no k or D properties there any more. Now it has A and F properties instead. Well, this won't do.

But do you see the __proto__ property right below that? Expand that and you'll see the available methods for the position object. Note the lat() and lng() methods there. These make a lot more sense, so try them:

map.setCenter( e.position.lat(), e.position.lng() );

What happened here: e.position is a LatLng object from the Google Maps API. The API objects have a number of undocumented internal properties, along with documented properties and methods. lat() and lng() are the documented methods to get the latitude and longitude from a LatLng object. The other properties you discovered are used internally in the API, but they aren't meant for use in your own code. Google runs all their JavaScript API code through a "minifier" that changes internal names arbitrarily to shorten the code but keeps the documented public names intact. So every few weeks when they update their API, any of the undocumented internal names may change.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!