How can i get current zoom level

6,199 views
Skip to first unread message

Vafa

unread,
Dec 6, 2010, 3:03:01 PM12/6/10
to google-map...@googlegroups.com
Hi everybody
I'm new in Google Maps. currently I need a change on this article for add a zoom level to MySQL.
How can I get a zoom level?
I think I need a listener for zoom level.
please tell me clear and simple!
the "map.getZoom(); " has not return the level of zoom and i got "map is not defined" on error console.
var url = "add.php?name=" + name + "&addre=<?php echo $_SESSION['MM_Username']; ?>&catid=" + catid +
                          "&lat" + latlng.lat() + "&lng=" + latlng.lng() + "&zoom=" + map.getZoom();

thanks

geoco...@gmail.com

unread,
Dec 6, 2010, 3:37:00 PM12/6/10
to Google Maps JavaScript API v3
On Dec 6, 12:03 pm, Vafa <gorey...@gmail.com> wrote:
> Hi everybody
> I'm new in Google Maps. currently I need a change on this article for
> add a zoom level to MySQL.
> How can I get a zoom level?

Depends on how you wrote your map code.

> I think I need a listener for zoom level.
> please tell me clear and simple!
> the "map.getZoom(); " has not return the level of zoom and i got "map
> is not defined" on error console.

Is your map variable global?

> var url = "add.php?name=" + name + "&addre=<?php echo
> $_SESSION['MM_Username']; ?>&catid=" + catid +
> "&lat" + latlng.lat() + "&lng=" + latlng.lng() + "&zoom=" +
> map.getZoom();

Please post a link to your map so we can help you.

-- Larry

>
> thanks

Vafa

unread,
Dec 7, 2010, 3:03:21 AM12/7/10
to Google Maps JavaScript API v3
1. I'm use this code:
http://code.google.com/apis/maps/articles/phpsqlinfo_v3.html
with a little changes in form filed.

2. please see the code (i think, no)

On Dec 6, 11:37 pm, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:

Vafa

unread,
Dec 9, 2010, 9:27:25 AM12/9/10
to Google Maps JavaScript API v3
this is all of my code
please tell me, why the map.getZoom(); not return any value.
see saveData() Function.


var marker;
var infowindow;

function initialize() {
var latlng = new google.maps.LatLng(36.4419, 46.4619);
var options = {
zoom: 13,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

var map = new
google.maps.Map(document.getElementById("map_canvas"), options);
var html = "<input type='text' id='name'/><input type='button'
value='Save & Close' onclick='saveData()'/>";
infowindow = new google.maps.InfoWindow({
content: html
});

google.maps.event.addListener(map, "click", function(event) {
marker = new google.maps.Marker({
position: event.latLng,
map: map
});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
});
}

function saveData() {
var name = escape(document.getElementById("name").value);
var latlng = marker.getPosition();
var url = "addn.php?name=" + name + "&lat" + latlng.lat() +
"&lng=" + latlng.lng() + "&zoom=" + map.getZoom();

downloadUrl(url, function(data, responseCode) {
if (responseCode == 200 && data.length <= 1) {
infowindow.close();
document.getElementById("message").innerHTML = "Location
added.";
}
});
}

function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;

request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request.responseText, request.status);
}
};

request.open('GET', url, true);
request.send(null);
}

Chad Killingsworth

unread,
Dec 9, 2010, 9:42:17 AM12/9/10
to google-map...@googlegroups.com
Please refrain from posting code to the group. We much prefer you post a link to your map.

However, your problem looks to be that your map variable is defined inside your initialize function and is therefore out of scope when map.getZoom() is called. Declare your map variable globally in the same way that marker and infowindow are declared globally.

Chad Killingsworth
Reply all
Reply to author
Forward
0 new messages