2015-10-01 4 views
0

Я пытаюсь отобразить маркер с меткой на картах Google. Я использую библиотеку markerwithlabel.js, которая позволяет мне это достичь. В принципе, я могу представить HTML + CSS в качестве метки маркера, и он будет отображаться на карте.Html css выравнивание в правой части изображения

Все работает хорошо в этом смысле, я просто хочу сделать его более красивым и отображать ярлык и длительность в ряд с маркером изображения.

Вот как это выглядит на данный момент:

enter image description here

Я хотел бы дисплей Norwich \n 1hour на правой стороне синего круга.

Не могли бы вы помочь мне с CSS и HTML.

HTML и JS:

 var markerHTML = '{0}<br>{1}'.format(places[i].name, '1hour'); 

     var marker = new MarkerWithLabel({ 
      position: new google.maps.LatLng(lat, lng), 
      draggable: false, 
      raiseOnDrag: true, 
      map: map, 
      labelContent: markerHTML, 
      labelAnchor: new google.maps.Point(22, 0), 
      labelClass: "labels", // the CSS class for the label 
      labelStyle: {opacity: 1.0}, 
      icon: "images/markers/blue_circle.png" 
     }); 

CSS:

.labels { 
    font-family: "Lucida Grande", "Arial", sans-serif; 
    font-size: 12px; 
    font-weight: bold; 
    text-align: left; 
    width: 100px; 
    white-space: normal; 
    word-spacing: 9999999px; 

    display: inline; 


    margin: 5%; 
    color: #000000; 

    filter:alpha(opacity=1); 

} 
+0

Это 'width' свойство может быть проблемой. Попробуйте удалить его или установить его шире. – jmargolisvt

+0

Просьба представить [Минимальный, завершенный, проверенный и читаемый пример] (http://stackoverflow.com/help/mcve), который демонстрирует проблему. – geocodezip

ответ

1

Измените значение LabelAnchor, чтобы найти ярлык, где вы хотите его:

var marker = new MarkerWithLabel({ 
    position: new google.maps.LatLng(lat, lng), 
    draggable: false, 
    raiseOnDrag: true, 
    map: map, 
    labelContent: markerHTML, 
    labelAnchor: new google.maps.Point(-10, 15), 
    labelClass: "labels", // the CSS class for the label 
    labelStyle: { 
     opacity: 1.0 
    }, 
    icon: "images/markers/blue_circle.png" 
}); 

proof of concept fiddle

фрагмент кода:

var geocoder; 
 
var map; 
 

 
function initialize() { 
 
    var map = new google.maps.Map(
 
    document.getElementById("map_canvas"), { 
 
     center: new google.maps.LatLng(37.4419, -122.1419), 
 
     zoom: 13, 
 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
 
    }); 
 
    geocoder = new google.maps.Geocoder(); 
 
    geocodeAddress("Norwich, UK", geocoder, map); 
 
    google.maps.event.addListener(map, 'center_changed', function() { 
 
    var places = []; 
 
    places[0] = { 
 
     name: "Norwich" 
 
    }; 
 
    var i = 0; 
 
    // var markerHTML = '{0}<br>{1}'.format(places[i].name, '1hour'); 
 
    var markerHTML = 'Norwich<br>1hour'; 
 
    var marker = new MarkerWithLabel({ 
 
     position: map.getCenter(), 
 
     draggable: false, 
 
     raiseOnDrag: true, 
 
     map: map, 
 
     labelContent: markerHTML, 
 
     labelAnchor: new google.maps.Point(-10, 15), 
 
     labelClass: "labels", // the CSS class for the label 
 
     labelStyle: { 
 
     opacity: 1.0 
 
     }, 
 
     icon: "https://maps.gstatic.com/intl/en_us/mapfiles/markers2/measle_blue.png" 
 
    }); 
 
    }); 
 
} 
 

 
function geocodeAddress(address, geocoder, resultsMap) { 
 
    geocoder.geocode({ 
 
    'address': address 
 
    }, function(results, status) { 
 
    if (status === google.maps.GeocoderStatus.OK) { 
 
     resultsMap.fitBounds(results[0].geometry.viewport); 
 

 
    } else { 
 
     alert('Geocode was not successful for the following reason: ' + status); 
 
    } 
 
    }); 
 
} 
 

 
google.maps.event.addDomListener(window, "load", initialize);
html, 
 
body, 
 
#map_canvas { 
 
    height: 100%; 
 
    width: 100%; 
 
    margin: 0px; 
 
    padding: 0px 
 
} 
 
.labels { 
 
    font-family: "Lucida Grande", "Arial", sans-serif; 
 
    font-size: 12px; 
 
    font-weight: bold; 
 
    text-align: left; 
 
    width: 100px; 
 
    white-space: normal; 
 
    word-spacing: 9999999px; 
 
    display: inline; 
 
    margin: 5%; 
 
    color: #000000; 
 
    filter: alpha(opacity=1); 
 
}
<script src="https://maps.googleapis.com/maps/api/js"></script> 
 
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerwithlabel/src/markerwithlabel.js"></script> 
 
<div id="map_canvas"></div>

+0

Невероятно. Благодаря! –

Смежные вопросы