views:

220

answers:

1

Has anyone been able to get this to work?

http://code.google.com/p/jquery-googlemap/

I only seem to get it to work if in debug:true, even then nothing appears like directions.

I am looking for a way either in PHP or jquery to set the address and have the map set it dynamically, as it's one page with the address of many places loaded with php. So the address changes every time.

A: 

I got it to work. First you need to get your own googlemap key from here.

Then you need to download the googlemap.js source. I got a copy from here.

Then you need to include the following references:

<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;sensor=false&amp;amp;key=PutYourKeyHere"&gt;&lt;/script&gt;
<script type="text/javascript" src="~/Scripts/googlemaps.js"></script>

<script type="text/javascript">
    jQuery(function($) {
        $("#map").googlemap({ addresses: ["1 ABC ST, NSW 2193 Sydney, Australia"] });
    });
</script>

And put a div in

<div id="map" style="width: 500px; height: 300px"></div>

Note: this plug-in seems to require an id not a class. For example if I define my div to have class="map" instead, $('.map').googlemap() fails with a null reference.

Keith Morgan
It doesn't work for me, no controls, it defaults to Australia
matthewb
It seems to be particular in the wording of the address. I got it work now. Still no way to get directions though
matthewb
If you need more than the simple functionality that googlemaps.gs provides, I suggest you write to the Google Maps API directly. For example, for directions consult http://code.google.com/apis/maps/documentation/services.html#Directions.
Keith Morgan