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

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.

Related

Upgrading Google Maps javascript v2 to v3 using Business Client IDs

I am using this link for Upgrading Google Maps JavaScript Application v2 To v3. Basically my approach is to get the output from api, parse it and load it using MapKit framework, which i am succeeded in doing it using this code.
My problem : As per the documentation,if we are using google maps for Business customer, we will need to use a Client ID in place of a Key.
so if I use this code:
<script src="https://maps.googleapis.com/maps/api/js?v=3&client=gme-myclientId&sensor=false" type="text/javascript"></script>
i am getting following output, where all the locations are plotted at single point (probably centre) :
if i use this code:
<script src="https://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script>
i will get the expected (correct) output as follows:
I also ran through this documentation for correct use of client id, but dint help.
I am using the same client id that was used for v2, hope that should not create any problem.
Thanks for all the comments to my question, which made me to solve the problem. So, i thought of sharing the solution.
when i am not using the client id,
<script src="https://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script>
the response structure is
"overview_path": [{
"jb": 37.785610000000005,
"kb": -122.41127000000002
}, … ];
But, on using the client id, say gme-myClientId
<script src="https://maps.googleapis.com/maps/api/js?v=3&client=gme-myClientId&sensor=false" type="text/javascript"></script>
the response structure is
"overview_path": [{
"hb": 37.785610000000005,
"ib": -122.41127000000002
}, …];
So, variation in jb,kb to hb,ib was causing the problem, since i was using the variables as key to get the values.
I was using a third party Code which internally follows this procedure.
I mailed Google enterprise support and they replied me back saying i might be using some of the undocumented variables in my Javascript library. The variable names are automatically generated when the library is minified and can (and often do) change on every release they push. The correct way is to use the documented API methods only.
link for using documented API methods can be found
Here
i modified my code to use like the below
var latT = someLocationObject.lat();
var longT = someLocationObject.lng();
and it worked for me.
Well, to use a client id like "gme-XXXXX" you need to buy a Google Maps for Business licence. Have you already buy one ?
Regards,

Google Maps V3 not loading (Asked & Answered)

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.

Google Maps problem

Well, I can't seem to "join the forum to post" on Google Maps itself, so I guess I'll ask here.
I recently noticed the following error that started happening on Google Maps Javascript API 3:
SCRIPT5007: 'undefined' is null or not an object main.js, line 17 character 197
This main.js file is the one used by Google Maps, not one on my own site.
The error seems to be caused by an undefined function being called, with the error happening here:
f.d[ac](f.b,c)
d[ac] is a function called apply, but f.d[ac] doesn't exist.
Anyone know how I can get it to work again? Or how to actually tell Google about the problem so they can do something about it?
Thanks.
Did you recently change from Google Maps JavaScript API v2 to v3? I had that error couple of times when using the v2 implementation of certain functions. But once again finding the source of your problem will be hard not having any code to take a look at.
Have you added a function to your own code called 'f'? That would cause this line to error.
function f(){
bla;
}

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.

How do I dynamically add points to a Google Map when the bounds change?

I can currently place static points in the map window:
var latlng = new GLatLng(lat, lng);
map.addOverlay(new GMarker(latlng, markerOptions));
And I know how to get the bounds of the window. I can also code a page that will take the bounds and return the points that are inside them in any format.
The problems I have now:
Does the moveend event capture all moves, including zoom changes? Or do I need to watch for that event separately?
How should I call my external datasource? (should I just do a JQuery $.get request?)
What should that datasource return?
How do I display that data on the map?
I'm using this in one of my sites. I think it's exactly what you are looking for. But be warned "gmaps-utility-library" plugins have some buggy/bad code so it's a good idea to go over it and double check if everything is working as it should (I haven't encountered any bugs in marker manager but in some other plugins from that library).
Here's reference and examples.
Even if you want to code your own this one is probably a good starting point.
EDIT
My answer for 3-4:
It really depends on situation. If it's static (you just need to manage a lot points on map > 300) then you could serve all points together with the page where the map is located in (as JavaScript array for example). If user interacts with data then probably it's better to use AJAX. If you use jQuery (or any other JS library) in your site then use ajax function from that library if not then go with the one which comes from gmaps. It's because it's nice to use same AJAX function in whole site instead of using 2 which does the same job.
If you are taking AJAX path you have 2 options:
Load all markers for whole map in one request.
Load markers that shows up on user screen + small margin.
If you expect that user wants to see the big picture or that he will want to see all/most of the points then go for option 1 + marker manager (like the one I recommended or your own similar).
If there's really a lot of points and user will never be interested in most of them then go for option 2 + manager or just this simple algorithm: Clear map -> Request points for map window bounds + magin / (Cache) -> Draw points -> Repeat for each move/zoom.
From personal experience (I've used both AJAX options) marker manager does quite nice job, can handle a lot points and overall user experience is a lot smoother then loading points for just viewport. Requesting new points and drawing them on map is quite laggy/choppy. Of course it depends on amount of points.
Here is a great example of making external calls to a data source from google:
Google Maps PHP and SQL
If you're storing the points in just an external javascript file then I would recommend using JSON format over XML as the XML parser that google maps uses is much slower than json.
Moveend yes captures any kind of changes.
If you're using only an external XML file then you can use google's function to call and download the XML file (seen in the link above), otherwise I would create a file that can be updated, and parse with json.
I believe it should return a JSON as i've discovered it is much quicker than XML parsing.
You would parse through the array and create a marker with each of these. Here is a good example of using json:
Jquery and Google Maps
Good Luck!
I'm currently doing something very similar to this, along with clustering on the server.
Yes, moveend will capture zoom changes.
If you're already using jQuery, a $.get request would work great.
I have tried returning both XML and JSON. These worked fine, but I discovered that parsing through these data formats caused the application to get significantly slower as more points were added to the database. I now return plain Javascript which I execute with eval(). I don't have a problem with this since I completely trust the source of the Javascript (me).
The Javascript function which adds a marker contains only the latitude, longitude, and id of the marker. The page already contains a Javascript array with all of the data for each marker, which can be accessed when the marker is clicked on.
That's how I'm doing it, but you could certainly accompish what you want to do with a number of methods.

Categories

Resources