Google Maps V3 not loading (Asked & Answered) - javascript

This question is already answered. I discovered what the problem is.
But, I'm posting the Q&A here because others may be in the same predicament.
My google map code came from samples I found on the web.
In the "bad" code there was a line that looked like this:
var latlng= new google.maps.LatLng(results[0].geometry.location.Ua, results[0].geometry.location.Va);
This code worked until last night.
Using firebug to inspect the objects, it turns out that location is now of the form: {Ta: number, Ua: number}
My immediate fix was to use the lat() and lng() methods whenever I required the lat and/or lng.
The other fix was to instantiate my map in a more intelligent fashion.
Yes, it was silly rely upon properties uncovered deep in an object using the firebug inspector. Yes, being a google maps noob and relying on copy paste with little or no knowledge reaped its just rewards.
But, doing a quick google seach found many folks (other than the "sample" I borrowed from) also using the .Va property directly.
Hence the post here in case this is their problem too.

In case you're interested in why this happened, it's simple: the sample was using undocumented internals of the API, so when Google updated the Maps JS file, it broke.
More specifically, Ua and Va were auto-generated variable names resulting from minification. It looks like Google removed a variable in the original source and the labels shifted up (Ua,Va → Ta,Ua).
I'll bet I know exactly how the author of the bad sample came up with his code. He inspected a LatLng (the type of object in location in your example) in his browser's dev tools, saw that those two oddly-named variables contained the data he wanted, and just went with it. Since the lat and lng methods are "hidden" in LatLng's prototype, he didn't notice them.
There are two lessons to be learned here:
Always use documented API methods; anything else is an implementation detail that is subject to change.
Don't trust the code on some dude's website is a good or even competent example of how to do things. This is especially true in the case of Google Maps, where there's extensive documentation and official examples.

Related

Here API findpickups example doesn't work

We are trying to use the findpickup api to find the best route for several waypoints. Despite the fact that we trying to understand how the pickup and drop params exactly work we were not able to get a successfully response from the example at
https://developer.here.com/documentation/routing-waypoints/dev_guide/topics/example-pickup.html
https://wse.ls.hereapi.com/2/findpickups.json?mode=fastest;car;traffic:disabled&start=waypoint0;50.115620,8.631210;pickup:GRAPEFRUITS,value:1000&departure=2016-10-14T07:30:00+02:00&vehicleCost=0.29&driverCost=20&maxDetour=60&restTimes=disabled&end=waypoint7;50.132540,8.649280&destination0=waypoint1;50.118578,8.636551;drop:APPLES,value:30&destination1=waypoint2;50.122540,8.631070;pickup:BANANAS&destination2=waypoint3;50.128920,8.629830;drop:BANANAS,value:30&destination3=waypoint4;50.118654,8.619956;pickup:APPLES&destination4=waypoint5;50.123998,8.640626;drop:PEACHES,value:50&destination5=waypoint6;50.130299,8.613031;pickup:PEACHES&apiKey={YOUR_API_KEY}
It is always complaining not finding a match for a street.
After finding a similar question on stackoverflow describing this problem
Here Map findpickups Cannot match onto a road link with 1000.0m search radius
we switched to the alternative domain. But now the entire pickup/drop thing confused us even more after reading the error message that drop-off point is missing.
Regardless where we are changing params for pickup/drop it stills complains that a contraint for pickup is not fullfilled.
Would be awesome if someone has any idea what is going wrong with the example from the HERE Docs.
And more importantly if someone can explain how the pickup/drop implementation actually works.
#HERE developer support
Thanks a lot for your reply.
My new additional notes would be too long as a comment. So I edited my questions with further information for describing the actually problem we have.
Obviously makes sense that GRAPEFRUIT has to be removed in a pickup waypoint. We already tried that. Sorry that we didn't mentioned that.
The thing is that in our use case will drop or pickup multiple items on each waypoint.
According docs this must work.
https://developer.here.com/documentation/routing-waypoints/dev_guide/topics/api-reference-type-waypoint.html .
Unfortunately it doesn't work. See following request
https://fleet.ls.hereapi.com/2/findpickups.json?driverCost=20&mode=fastest;car&vehicleCost=0.20&start=wp1;50.41256,8.02943&destination1=wp2;50.0766,8.22699;pickup:item1&destination2=wp3;50.07735,8.22185;pickup:item2&destination3=wp4;50.06563,8.19155;drop:item1,value:100;drop:item2,value:100&end=wp5;50.41256,8.02943&apikey=YOUR_API_KEY
Would love to get some hints and a solution for our use case.
You would have to switch to the new domain https://fleet.ls.hereapi.com/2/findpickups.json and also change the departure time format as well as remove the pickup condition for the GRAPEFRUITS. The below request should work:
https://fleet.ls.hereapi.com/2/findpickups.json?mode=fastest;car;traffic:disabled&start=waypoint0;50.115620,8.631210&driverCost=20&maxDetour=60&restTimes=disabled&destination0=waypoint1;50.118578,8.636551;drop:APPLES,value:30&destination1=waypoint2;50.122540,8.631070;pickup:BANANAS&destination3=waypoint4;50.118654,8.619956;pickup:APPLES&destination4=waypoint5;50.123998,8.640626;drop:PEACHES,value:50&destination5=waypoint6;50.130299,8.613031;pickup:PEACHES&departure=2016-10-14T07:30:00&vehicleCost=0.29&end=waypoint7;50.132540,8.649280&destination2=waypoint3;50.18920,8.629830;drop:BANANAS,value:30&apikey=YOUR_API_KEY
We have reported the issue to API team, ask is to correct/simplify the example.

Z-index into xml for Google maps with custom markers

I am tring to introduce z-index to my map so I can stack custom markers (http://www.ghd.com/global/locations/canada-1/)
I have read there are properties that exist in v3 that allow this to be set. I am wondering in the short term how to create function that means that property can than be specified in my xml for my example above.
I have seen exmaple where it is set in the javascript, but in this example the markers are all set there as well (http://econym.org.uk/gmap/zindex.htm)
I realize this is probably quite a basic solution, I am not that advanced in javascript unfortunately. Any assistance would be appreciated.
Look at this. This is open source map api. You can use bing,google,openstreet...
But you must known little knowledge javascript.

Subgurim Maps control causing javascript errors ("GUnload undefined")

I want to implement a Google Map on my .NET page. I used the tool from Subgurim,
I could add the components well, but when browsing the page, I get tons of Javascript errors like:
GUnload is undefined
And the map is not shown. I read many posts describing my problem, but the only hint seems to be the maps API was not loaded.
I got a API key from Google. I am not very familiar with the interface; I activated both Google maps API services (v2 and v3) and got a key from "API access" for both separately.
I downloaded the Subgurim Maps version 3.4.1.
string streetAddress = "100 Russell St. Melbourne. VIC. 3000. Australia";
string mapKey = ConfigurationManager.AppSettings["googlemaps.subgurim.net"];
Subgurim.Controles.GeoCode geoCode = GMap1.getGeoCodeRequest(streetAddress, mapKey);
Subgurim.Controles.GLatLng gLatLng = new Subgurim.Controles.GLatLng(geoCode.Placemark.coordinates.lat, geoCode.Placemark.coordinates.lng);
GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal);
Subgurim.Controles.GMarker oMarker = new Subgurim.Controles.GMarker(gLatLng);
GMap1.addGMarker(oMarker);
Without access to your code, I deduce that you have included the Version 3 <script> tag but have coded the map in Version 2. Thus your code includes lots of G objects, including GUnload, which are not included in Version 3 and the API knows nothing about.
The immediate solution would be to include the Version 2 script. The full solution (since Version 2 is deprecated) is to convert the map to Version 3. I've no idea whether Subgurim makes that possible.
The new (short) key works for Version 3 and Version 2.
The problem was that the GMap control I used was in part of the page that was set visible="false". This caused the Javascript error.

Student's t distribution in JavaScript for Google Spreadsheet

Google Spreadsheets currently does not support the standard function TDIST - i.e. the Student's t-distribution. This function is critical for calculating p-values.
It seems that this is related to the fact that no integral-using functions (AFAICT) are implemented either.
However, Google Docs allows people to add and publish their own scripts, in JavaScript.
So ideally we should have something like:
function tdist(t_value, degrees_of_freedom, two_tailed [defaults true]) {...}
Anyone know of either an extant implementation of this (my google-fu has not turned up one, but may be weaker than yours) or a good idea for how to do it?
I'd like to publish this together with some other useful functions that are currently calculable but a bit of a pain (like Student's t-test itself).
Thanks!
Here you go.
Google Sheets does now include the TDIST function (if you've switched to the new version).
http://www.math.ucla.edu/~tom/distributions/tDist.html - view source.

What causes Google Maps javascript exceptions?

I pretty consistently get GMaps API javascript exceptions that look like the following:
Ve.k is null or not an object (FF & IE)
b.k is null or not an object (FF & IE)
a is null (FF)
a.$e is undefined (FF)
Uncaught TypeError: Cannot read property 'k' of undefined (chrome)
Often the exception occurs during an eval of some expression in javascript in the bowels of the GMaps API
Almost anything can cause one of these to pop up, displaying an overlay on the map or a mouse click event for example.
I've been scouring my code for some time looking for offending overlays, and event handlers, but so far no relationship found. I've had this happen on a naked map with no overlays or handlers active.
Certain versions of the API will not crash on certain browsers, but it's hit and miss and I still have this sinking susspicion that something in the environment is giving GMaps a hard time (eg. maybe Facebook Connect, Google Analytics, my code...)
Does anyone have a handle on what causes these?
After spending quite a bit of time rolling back operations that affected the map 1 by 1, I finally got to the line(s) that caused this problem.
First, if I removed the call to setUIToDefault() the problem went away, this was unacceptable to me both because I wanted the default UI and that's a lame way to solve the problem. So many more map operations later I came to the GWT calls:
mapWidget.setHeight()
mapWidget.setWidth().
For those not familiar with GWT these two calls will ultimately translate to the following javascript template call:
element.style['height'] = height;
where 'element' in this case is the div that contains the map and height on the RHS of the expression is something like "690px".
That was all it took to derail the maps API.
The fix? Setting the size of the map div prior to instantiating the map.
You tell me, bug in the maps api or just a major feature lack? I'm going to check w/ the maps folks.
Just the perils of using a minified, obfuscated Javascript library I am afraid. There is no discrete group of errors that result in the exceptions you are seeing, but you can be sure that they are a result of a bug in your own code. I use Google maps pretty extensively and have regularly seen these types of errors. In 100% of cases, the bug was mine.
If you post (either here or in new questions) specific examples of pages that generate these errors, we can check them out and hopefully fix them.
I would have to guess it would be your code (not to say your a bad programmer) or another library interfering. I've been using the Google MAPS API happily for about 1 year now* and never had the first exception. The only time I've ever gotten an error message was when I was adding the balloon thingy.
*The website looks like crap but it was a high school project for my county fair and I couldn't use any server side stuff.
Edit: After reading your comment I'm wondering if you included a proper DOCTYPE? Check and see if you have it.

Categories

Resources