[LRUG] Introduction and a request for JS help

sole listas at soledadpenades.com
Fri Jan 23 08:12:38 PST 2009


Hi Vahagn,

Just had a little look at your application.js file and compared it to
the code of a little website of mine (http://mapspam.net). There's
something that doesn't look right in your file. In the initialize
function, first line says

if (GBrowserIsCompatible() && typeof gyms != 'undefined') {

I believe it should be

if (GBrowserIsCompatible() && typeof(gyms) != undefined) {

note that now undefined doesn't have the single quotes around.  It's a
bit like comparing 'nil' and nil ;-)

Anyway for some magic reason it gets executed since the map is launched
into div#map, without any console errors (I'm using firebug) although it
somehow ends in a weird state. I have the feeling it might be due to the
coordinates and zoom level you're sending to it.

I would suggest to strip the script down to the bare minimum, comment
out all the bounds stuff, and make sure the markers are shown in the map
even if it's not centered and scaled to the optimum level. I.e. just use
something like

map.setCenter(new GLatLng(0, 0), 1);

as I do in my ultrasimple website and continue from there.


Also I see we're not creating the markers the same way. In the createMarker function you're doing

GEvent.addListener(marker,"click", function() {

    map.openInfoWindowHtml(latlng, html);
});


whereas I have something on the lines of

var marker0 = new GMarker(new GLatLng(52.35,4.9167), baseIcon);
GEvent.addListener(marker0, 'click', function() {
	marker0.openInfoWindowHtml('<strong>Amsterdam (Netherlands)</strong>,<br />78 spam messages.<br />Ranking:  1/30');
});

note I'm using *the marker's* openInfoWindowHtml method, not the map's.


Also if you don't need all the js files from prototype & co, you could
maybe try to temporarily not link to them while you sort out what's
wrong with the map. Sometimes... you know, js libraries don't play along
nicely.

It's a pity I can't download your script, modify and test it locally as
it was a normal js file since google maps won't execute anything if you
haven't registered with them the domain where you want to execute the js
code.

Hope it's helpful!

Vahagn Hayrapetyan wrote:
> Hello,-
>
> my name is Vahagn and I'm new to this group. I'm a Ruby / Rails
> developer currently based in Denmark but will be moving to the UK soon.
>
> My main background is in Java and .NET; in 2008, after hearing the
> call, I've decided to join the community of recovering PHP coders,
> enterprise survivors, and plain geniuses and migrated to Rails. I like
> it so far.
>
> I've just released a brand new webapp that allows for searching for
> the world's functional gyms. One thing I'm not an expert at is
> JavaScript and the Google APIs. Too bad for me - the only part of the
> app that does not work is where te search results are shown on Google
> Maps. Here's an example:
>
> http://functionalgyms.com/gyms/locate?address=San+Diego&within[miles]=1
> <http://functionalgyms.com/gyms/locate?address=San+Diego&within%5Bmiles%5D=1>
>
> (A search for a gym in San Diego within the radius of 1 mile).
>
> I've asked on the Google Maps API forum. I've debugged. I've asked the
> author of the recipe, Andre Lewis, directly (Advanced Rails Recipes,
> PragProg, 2008, the recipe is called "Mark locations on a Google
> Map"). He's not sure what the problem is. I'm not sure either (it's
> not my code). I've asked at the ruby-forum.com
> <http://ruby-forum.com>. So far, to no avail.
>
> To cut a long story short, I'm looking for a person with some insight
> into JavaScript and Google Maps, that would be so kind as to show me
> where the error / fault is so that I can get rid of this enigma and
> get my webapp to fully functional. I promise to drench this person in
> beer (on the inside), as one of my first duties upon arrival in the UK.
>
> As to the complexity of the task: I'm not posting any code here as
> this is just an initial request for help, but it's a really short JS
> function (two really - one nested within the other), written exactly
> as in the book, that does not work as intended. All the important
> background stuff (like the geocoding of addresses with the Rails
> GeoKit plugin), are in place and working fine. I have a feeling that
> it is some banal but hard-to-see-for-a-newbie JS quirk.
>
> Anyone?
>
> Best,
> Vahagn
> ------------------------------------------------------------------------
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>   




More information about the Chat mailing list