google maps API, how to start

1,977 views
Skip to first unread message

Andrew Balakhanov

unread,
Aug 4, 2010, 6:22:21 AM8/4/10
to Google Maps JavaScript API v3
Good day, dear developers.
Can you please help me in advice.
So, I try to start use API for Google maps. And I try simple example,
but it doesn't work.
I have code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>

<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=true">
</script>

<script type="text/javascript">
var GOOGLEMAPS = "http://maps.google.com/maps?
f=q&hl=en&ie=UTF8&z=10&iwloc=addr&om=1&q=";
var latitude = "53.902550";
var longitude = "27.563101";

var w = window.open(GOOGLEMAPS+latitude+","+longitude
+"&geocode=","map");

//Init a new map
var map = new GMap2(document.getElementById('map'));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(56.87, 14.80), 11);
// Creating a new marker
var marker = new GMarker(new GLatLng(56.87, 14.80))
// Adding a click-event to the marker
GEvent.addListener(marker, 'click', function() {
// When clicked, open an Info Window
marker.openInfoWindowHtml('Some text');
});
// Add marker to map
map.addOverlay(marker);


</script>

<title>Insert title here</title>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>

</html>

But it's leads to error :
GMap2 is not defined
var map = new GMap2(document.getElementById('map'));

Rossko

unread,
Aug 4, 2010, 6:32:19 AM8/4/10
to Google Maps JavaScript API v3
> But it's leads to error :
> GMap2 is not defined
> var map = new GMap2(document.getElementById('map'));

You are jumbling up different examples. Stick to just one to begin
with. The error is due to trying to use a v2 API method without
loading the v2 API.

Start again, here
http://code.google.com/apis/maps/documentation/javascript/tutorial.html
(if you want to use v3 API)

Andrew Balakhanov

unread,
Aug 4, 2010, 7:12:43 AM8/4/10
to Google Maps JavaScript API v3
Thank you, mr. Rossko.
But I didn't understand, which URL I should include, that API will
loaded ?

Rossko

unread,
Aug 4, 2010, 8:20:59 AM8/4/10
to Google Maps JavaScript API v3
> But I didn't understand, which URL I should include, that  API will
> loaded ?

I'm not telling you. Read the tutorial
http://code.google.com/apis/maps/documentation/javascript/tutorial.html

am63

unread,
Aug 4, 2010, 11:05:50 AM8/4/10
to Google Maps JavaScript API v3
Please read thoroughly the tutorial Rossko gave you and completely
FORGET the code above (a copy/paste from several tutorials, or
outdated pages, not from the same API release... that's why you get
some errors... the class GMap2 does not exist in V3, for example).

Also, when importing the API in the SCRIPT tag, please include the
following attribute to be sure to get the latest v3 release ; the
sensor parameter can be set to false, unless your web application is
run from a device with a GPS (not likely for a PC, but if the
application is devised for a mobile phone, that's possible).

script type="text/javascript"
src="http://maps.google.com/maps/api/js?v=3&sensor=false">
</script>

subbu raj

unread,
Aug 4, 2010, 8:42:39 AM8/4/10
to google-map...@googlegroups.com
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
 html { height: 100% }
 body { height: 100%; margin: 0px; padding: 0px }
 #map_canvas { height: 100% }
</style>


            type="text/javascript"></script>


<script type="text/javascript">
function initialize() {
var latitude = "53.902550";
var longitude = "27.563101";
var map = new GMap2(document.getElementById('map'));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(56.87, 14.80), 11);
// Creating a new marker
var marker = new GMarker(new GLatLng(56.87, 14.80))
// Adding a click-event to the marker
GEvent.addListener(marker, 'click', function() {
 // When clicked, open an Info Window
 marker.openInfoWindowHtml('Some text');
});
// Add marker to map
map.addOverlay(marker);
}


</script>

<title>Insert title here</title>
</head>
<body onLoad="initialize()">
 <div id="map" style="width:100%; height:100%"></div>
</body>

</html>

In the place KEY HERE just paste ur key it will work.........


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Federico Ulfo

unread,
Aug 4, 2010, 4:44:14 PM8/4/10
to google-map...@googlegroups.com
I advice to pass directly to the new version of google maps, the v3 api.
If you want with the examples here there's a bunch, really easy
http://code.google.com/apis/maps/documentation/javascript/examples/index.html

instead if you want to study the google maps documentation, you can start here:
http://code.google.com/apis/maps/documentation/javascript/basics.html


and if you want check this out
http://www.federicoulfo.it/maps/
just some experiment of mine


cheers,
Federico



2010/8/4 am63 <assistancem...@gmail.com>
Reply all
Reply to author
Forward
0 new messages