Hi. I have been trying to set the center and zoom lvl on google map but i cant figure out whats wrong with the code or if its a bug.
Just so shorten down the code a bit:
The problem is here:
I set:
var bounds = new GLatLngBounds();
Then loops trough all the addresses
gets the point from geocoder.getLatLng
Then I use: bounds.extend(point);
And at last i use
map.setZoom(map.getBoundsZoomLevel(bounds)); map.setCenter
(bounds.getCenter());
The result is that the map is fully zoomed ut with zoom lvl 2 i think,
and i centerd at world map
Probarbly becurse of this code.
map.setCenter(new GLatLng(0,0),0);
Debug data: The bounds Var contains this:
((57.29577951308232, 180), (-57.29577951308232, -180)) Ga=Object
ya=Object __type=
I guess this data is wrong.
setLocation: function(classRoot,map){
var geocoder = new GClientGeocoder();
var address = classRoot.obj.address;
var bounds = new GLatLngBounds();
classRoot.mapPoints = new Array();
if (geocoder)
{
address.each(function(adr,i){
geocoder.getLatLng(
adr,
function(point)
{
if (!point){
alert(address + " not
found");
}else{
if(i == 0){
//
map.setCenter(point, classRoot.obj.zoomLvl);
}
var marker = new
GMarker(point);
map.addOverlay(marker);
bounds.extend(point);
classRoot.mapPoints[i]
= point;
}
});
});
map.setZoom(map.getBoundsZoomLevel(bounds));
map.setCenter(bounds.getCenter());
}
}
FULL SURCE CODE.
The surce code:
Created with Prototype: 1.6.2
var googleMap = Class.create(
{
initialize: function(obj)
{
var classRoot = this;
var root = window;
this.obj = obj;
if (root.GBrowserIsCompatible()) {
var map = new GMap2($(classRoot.obj.map), {size: new
GSize
(classRoot.obj.width,classRoot.obj.height) });
map.setCenter(new GLatLng(0,0),0);
if(classRoot.obj.address != ''){
classRoot.setLocation(classRoot,map);
if(classRoot.obj.boundaries){
GEvent.addListener(map,"moveend", function() {
var onMap = false;
var mapBounds = map.getBounds();
var southWest =
mapBounds.getSouthWest();
var northEast =
mapBounds.getNorthEast();
var geocoder = new
GClientGeocoder();
classRoot.mapPoints.each(function(point,i){
if(((southWest.lat() <
classRoot.mapPoints[i].y) &&
(northEast.lat() > classRoot.mapPoints[i].y)
&& (southWest.lng() <
classRoot.mapPoints[i].x) &&
(northEast.lng() > classRoot.mapPoints[i].x))){
onMap = true;
}else{
onMap = false;
}
if(onMap){
if (geocoder)
{
geocoder.getLocations(classRoot.mapPoints[i], function
(addresses) {
if(addresses.Status.code == 200) {
var result = addresses.Placemark[0];
console.log(result.address);
}
});
}
}else{
console.log('its not on
the map');
}
});
});
}
}
if(classRoot.obj.controls){
classRoot.addControls(map);
}
}
},
setLocation: function(classRoot,map){
var geocoder = new GClientGeocoder();
var address = classRoot.obj.address;
var bounds = new GLatLngBounds();
classRoot.mapPoints = new Array();
if (geocoder)
{
address.each(function(adr,i){
geocoder.getLatLng(
adr,
function(point)
{
if (!point){
alert(address + " not
found");
}else{
if(i == 0){
//
map.setCenter(point, classRoot.obj.zoomLvl);
}
var marker = new
GMarker(point);
map.addOverlay(marker);
bounds.extend(point);
classRoot.mapPoints[i]
= point;
}
});
});
map.setZoom(map.getBoundsZoomLevel(bounds));
map.setCenter(bounds.getCenter());
}
},
addControls: function(map){
map.removeMapType(G_HYBRID_MAP);
map.addControl(new GLargeMapControl());
var mapControl = new GMapTypeControl();
map.addControl(mapControl);
}
});
Event.observe(window, 'load', function()
{
if($('projectMap')){
var address = new Array();
address[lb]0[rb] = 'Kvernhusrenen 36, 5200 os';
address[lb]1[rb] = 'Kanalveien 88, 5068 Bergen';
var newGoogleMap2 = new googleMap(
{
map : 'projectMap',
width: 359,
height: 588,
address: address,
zoomLvl: 12,
controls: true,
boundaries: true
});
}
});
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---
