Google Maps API v3'te, işaretleyicinin yanında özel metin yazmak mümkün mü? veya bunu yapmak için sadece bilgi penceresini kullanabilir miyim?Google Maps API v3'te özel metin yazmak mümkün mü?
cevap
Özel metni göstermek için özel bir yer paylaşımı oluşturmanız gerekir. Aşağıda resmi Google dokümanlarından uyarlanmış bir örnek verilmiştir. Ayrıca, daha fazla "şık" bilgi pencereleri
<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script>
//adapded from this example http://code.google.com/apis/maps/documentation/javascript/overlays.html#CustomOverlays
//text overlays
function TxtOverlay(pos, txt, cls, map) {
// Now initialize all properties.
this.pos = pos;
this.txt_ = txt;
this.cls_ = cls;
this.map_ = map;
// We define a property to hold the image's
// div. We'll actually create this div
// upon receipt of the add() method so we'll
// leave it null for now.
this.div_ = null;
// Explicitly call setMap() on this overlay
this.setMap(map);
}
TxtOverlay.prototype = new google.maps.OverlayView();
TxtOverlay.prototype.onAdd = function() {
// Note: an overlay's receipt of onAdd() indicates that
// the map's panes are now available for attaching
// the overlay to the map via the DOM.
// Create the DIV and set some basic attributes.
var div = document.createElement('DIV');
div.className = this.cls_;
div.innerHTML = this.txt_;
// Set the overlay's div_ property to this DIV
this.div_ = div;
var overlayProjection = this.getProjection();
var position = overlayProjection.fromLatLngToDivPixel(this.pos);
div.style.left = position.x + 'px';
div.style.top = position.y + 'px';
// We add an overlay to a map via one of the map's panes.
var panes = this.getPanes();
panes.floatPane.appendChild(div);
}
TxtOverlay.prototype.draw = function() {
var overlayProjection = this.getProjection();
// Retrieve the southwest and northeast coordinates of this overlay
// in latlngs and convert them to pixels coordinates.
// We'll use these coordinates to resize the DIV.
var position = overlayProjection.fromLatLngToDivPixel(this.pos);
var div = this.div_;
div.style.left = position.x + 'px';
div.style.top = position.y + 'px';
}
//Optional: helper methods for removing and toggling the text overlay.
TxtOverlay.prototype.onRemove = function() {
this.div_.parentNode.removeChild(this.div_);
this.div_ = null;
}
TxtOverlay.prototype.hide = function() {
if (this.div_) {
this.div_.style.visibility = "hidden";
}
}
TxtOverlay.prototype.show = function() {
if (this.div_) {
this.div_.style.visibility = "visible";
}
}
TxtOverlay.prototype.toggle = function() {
if (this.div_) {
if (this.div_.style.visibility == "hidden") {
this.show();
} else {
this.hide();
}
}
}
TxtOverlay.prototype.toggleDOM = function() {
if (this.getMap()) {
this.setMap(null);
} else {
this.setMap(this.map_);
}
}
var map;
function init() {
var latlng = new google.maps.LatLng(37.9069, -122.0792);
var myOptions = {
zoom: 4,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Hello World!"
});
customTxt = "<div>Blah blah sdfsddddddddddddddd ddddddddddddddddddddd<ul><li>Blah 1<li>blah 2 </ul></div>"
txt = new TxtOverlay(latlng, customTxt, "customBox", map)
}
</script>
<style>
.customBox {
background: yellow;
border: 1px solid black;
position: absolute;
}
</style>
</head>
<body onload="init()">
<div id="map" style="width: 600px; height: 600px;">
</div>
</body>
</html>
Bu harika. Kafamı çiziyorum ve Google'ın bunu neden varsayılan olarak eklemediğini merak ediyorum. –
Etiket metni boyutunu değiştirmenin bir yolu var mı? Stil bloğuna 'font-size: 30px' eklemek işe yaramıyor. –
Bir çekicilik gibi çalışır! Mükemmel cevap! –
farkla Metin Yerleşimi eklemenin en kolay yolu https://github.com/googlemaps/js-map-label
var mapLabel = new MapLabel({
text: 'Test',
position: new google.maps.LatLng(50,50),
map: map,
fontSize: 20,
align: 'right'
});
den MapLabel
sınıf kullanmaktır için this library kullanabilirsiniz Bu metin statiktir, bir işaretleyici ve bir görüntü kullanabilirsiniz:
var label = new google.maps.Marker({
position: new google.maps.LatLng(50,50),
map: map,
icon: "/images/mytextasanimage.png"
});
Gerçekten, bu çalışır. Çok iyi ! – Zl3n
- 1. Google Maps API (statik)
- 2. Google maps api Çember eğimi?
- 3. Google Maps API v3: Özel işaretleyici
- 4. Google Maps API Otomatik Tamamlayıcı Özel Sonuçlar
- 5. Google Maps API Özel Pop-Up
- 6. google maps API for C#
- 7. Google Static Maps API:
- 8. google maps api
- 9. Google Maps API - Sınıfındaki Sorunlar
- 10. API ile Özel Google Haritalar Katmanları mı? Bu, Google Maps API v3 ilgili olduğunu
- 11. Android'de bir metin görünümünde dikey olarak yazmak mümkün mü?
- 12. JavaScript kullanarak google sayfalarına veri yazmak mümkün mü?
- 13. getpaths() çokgenler google maps api
- 14. bir Google Maps API çağrısı
- 15. GWT + Google Maps API v3
- 16. Google Maps API işlevi map.getCenter()
- 17. Google Maps API directionsService.route farklı
- 18. Google Maps Katmanlardaki Api işareti
- 19. Google Maps API ve GeoJSON
- 20. google maps api placesservice'yi okuyamadı
- 21. Google Maps API ile Google Maps Engine arasında mı?
- 22. iOS Google Maps Api Döşenmiş Kaplamalar
- 23. Google Maps API 3: Sağ Tıklama Koordinatlarını Alın
- 24. Google Maps: iOS'ta özel konumSource
- 25. Google Maps API v3 Özel Simgelerle İlgi Çekici Noktalar
- 26. Google Maps API Geocode Eşzamanlı olarak
- 27. Google Maps v3, metin kutusuyla özel denetim: giriş yapamıyor
- 28. Çokgen çizimi tamamlandığında, google maps api v3
- 29. Google Maps api V3 güncelleme işareti
- 30. XmlWriter ile belleğe XML yazmak mümkün mü?
bakmak mümkün değil ... tek yolu şeffaf InfoBox penceresi oluşturmak ve üzerine yazı yazmak gibi ... yanlış mıyım? – user198003
Google harita statik harita API'sinde işaretçiye özel metin (büyük ihtimalle bir kelime) ekleyebilir miyim ..? – Jay