2012-02-22 3 views
1

Tous, J'ai le code suivant pour afficher mes cartes:Google Maps ne Centrage sur Lat/Long

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 
function addLoadEvent(func) { 
var oldonload = window.onload; 
if (typeof window.onload != 'function'){ 
    window.onload = func 
} else { 
    window.onload = function() { 
     oldonload(); 
     func(); 
    } 
} 
} 

var map, 
    infowin=new google.maps.InfoWindow({content:'moin'}); 
function loadMap() 
{ 
    map = new google.maps.Map(
    document.getElementById('map_vendor'), 
    { 
     zoom: 15, 
     mapTypeId:google.maps.MapTypeId.ROADMAP, 
     center:new google.maps.LatLng(<?php echo $lat; ?>, 
            <?php echo $long; ?>) 
    }); 

    addPoints(myStores); 
} 

function addPoints(points) 
{ 
    //var bounds=new google.maps.LatLngBounds(); 
    for (var p = 0; p < points.length; ++p) 
    { 
    var pointData = points[p]; 
    if (pointData == null) {map.fitBounds(bounds);return; } 
    var point = new google.maps.LatLng(pointData.latitude, pointData.longitude); 
    //bounds.union(new google.maps.LatLngBounds(point)); 
    createMarker(point, pointData.html); 
    } 
    //map.fitBounds(bounds); 

} 

function createMarker(point, popuphtml) 
{ 
    var popuphtml = "<div id=\"popup\">" + popuphtml + "<\/div>"; 
    var marker = new google.maps.Marker(
    { 
     position:point, 
     map:map 
    } 
); 
    google.maps.event.addListener(marker, 'click', function() { 
     infowin.setContent(popuphtml) 
     infowin.open(map,marker); 
    }); 

} 

function Store(lat, long, text) 
{ 
    this.latitude = lat; 
    this.longitude = long; 
    this.html = text; 
} 

var myStores = [<?php echo $jsData;?>, null]; 
addLoadEvent(loadMap); 
</script> 

Le $ jsData est réglé avec le code suivant:

$lat = get_post_meta($post->ID,'latitude',TRUE); 
$long = get_post_meta($post->ID,'longitude',TRUE); 
$post_id = $post->ID; 
$get_post_info = get_post($post_id); 
$name = $get_post_info->post_title; 
$jsData = $jsData . "new Store($lat, $long, '$name'),\n"; 

Le point s'affiche correctement, mais ma carte n'est pas centrée correctement. Mes cartes sont toujours au sud-est de l'endroit du point et juste un peu, mais j'aimerais qu'il soit centré sur le point. Comment puis-je faire cela?

EDIT: Voici le CSS que vous avez demandé. C'est un thème donc je suis désolé si c'est fou:

#map_vendor{ 
padding:10px; 
width:925px; 
height:300px; 
} 
.styled-image, .the-post-image figure, .styled-slideshow, .gallery .gallery-icon a { 
border-color: #C9CBCD; 
background: #F7F7F7; 
background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#E7E8EB)); 
background: -moz-linear-gradient(top, #fff, #E7E8EB); 
background: linear-gradient(#fff, #E7E8EB); 
-pie-background: linear-gradient(#fff, #E7E8EB); 
} 
.styled-image, .the-post-image a figure, .gallery .gallery-icon a { 
-webkit-transition: all 0.15s ease-in-out; 
-moz-transition: all 0.15s ease-in-out; 
transition: all 0.15s ease-in-out; 
} 
.styled-image, .the-post-image figure, .styled-slideshow, .gallery .gallery-icon a { 
display: block; display: inline-block; outline: none; padding: 6px; 
border: 2px solid #C9CBCD; border-width: 1px 1px 2px; 
-webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px; /* border radius */ 
/* gradient background */ 
background: #F7F7F7; 
background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#E7E8EB)); 
background: -moz-linear-gradient(top, #fff, #E7E8EB); 
background: linear-gradient(#fff, #E7E8EB); 
-pie-background: linear-gradient(#fff, #E7E8EB);  
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.2); -moz-box-shadow: 0 0 3px rgba(0, 0, 0, 0.2); box-shadow: 0 0 3px rgba(0, 0, 0, 0.2); /* box shadow */ 
-webkit-background-clip: padding-box; /* smoother borders with webkit */ 
} 

Merci!

Répondre

1

Que signifie "point"?

Actuellement, vous définissez le centre sur $ lat et $ lng, mais il n'y a pas de marqueur (point?) À cette position (à moins que $ jsData ne soit les mêmes coordonnées).

+0

J'ai mis à jour ma question originale afin que vous puissiez voir cela. Cependant vous avez raison. Le $ jsData a les mêmes coordonnées que j'essaye de placer le centre de la carte. – user1048676

+0

Désolé, veuillez fournir une démo du problème, sinon je ne peux pas vous aider. Je testais cela, le marqueur (bien sûr) est centré. Peu importe si le zoom est 1 ou 15, il sera toujours placé à la même position dans la fenêtre, il doit donc être centré (dans mon test). –

+0

C'est sur mon localhost donc je ne peux pas vraiment vous montrer. J'ai essayé de créer un jsfiddle pour voir si cela a fonctionné mais il me manque quelque chose car il ne se charge pas correctement. J'ai essayé de coder manuellement les valeurs et cela ne s'affichait toujours pas correctement sur mon site. Voici le jsfiddle donc vous pouvez voir si vous pouvez le faire fonctionner: http://jsfiddle.net/Lrjmt/ – user1048676

Questions connexes