How to load a GMAP into a Div using Ajax. cross-domain problem??

J

Javier

Hi,
I have a problem trying to load a GoogleMaps map into a Div using
Ajax.
Basically I have main.php with a Div inside that is loaded with the
content of other pages like map.php.
When I try to load the content into the Div, It recognizes javascript
code, but no the javascript code of the map, so I think it's a cross-
domain problem.....
My question is: Is it possible to avoid this problem? How can I do a
very simple action like loading a Gmaps map into a Div?
Thanks for your time.
Javier.
 
B

Bart Van der Donck

Javier said:
I have a problem trying to load a GoogleMaps map into a Div using
Ajax.
Basically I have main.php with a Div inside that is loaded with the
content of other pages like map.php.
When I try to load the content into the Div, It recognizes javascript
code, but no the javascript code of the map, so I think it's a cross-
domain problem.....
My question is: Is it possible to avoid this problem? How can I do a
very simple action like loading a Gmaps map into a Div?

Hard without looking at the code, but at first sight I would not
suspect a cross-domain problem, since the javascripts are loaded from
Google and should always be executable (no cross-domain limitation
here).

You mention AJAX, so I suppose you are using Google's AJAX API. Could
you run the following test in a standalone page (map.html) ?

--------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Load Google map in a div</title>
<script type="text/javascript"
src="http://www.google.com/jsapi?key=YOURKEYHERE"></script>
</script>
<script type="text/javascript">
google.load('maps','2');
function loadmapdiv() {
var map = new google.maps.Map2(document.getElementById('mydiv'));
map.setCenter(new google.maps.LatLng(50,5),5);
}
</script>
</head>
<body>
<div id="mydiv"
style="width:300px; height:300px; background-color:silver;"></div>
<a href="#" onClick="loadmapdiv(); return false;">Load map in div</a>
</body>
</html>
--------------------------------------------------------------------

Then embed it into a PHP file (map.php), and finally embed that PHP-
file into another one (main.php).

Hope this helps,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top