Google Maps Javascript API V3 how to Placemark show name only

ぃ、小莉子 提交于 2019-12-08 07:37:34

问题


As a Title, I want show Placemark with Name field. Basically, google map show Placemark with blue balloons. but i don't wanna see this blue ballons. Just show Name only like google earth. is it possible with google maps javascript api?

=============KML===============

<Folder>
   <name>Point Features</name>
   <description>Point Features</description>
   <Placemark>
     <description><![CDATA[LABEL<BR><BR><B>ELEVATION</B> = -2147483648.0000000]]></description>
     <name>lnd_a</name>
     <Point>
       <coordinates>126.3680042851,34.7669071990,-2147483648.000</coordinates>
     </Point>
   </Placemark>
   <!-- MY KML FILE HAS MORE LINE -->
</Folder>

=============Script Source===============

<script type="text/javascript"src="https://maps.google.com/maps/api/js?sensor=false"></script>

<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(34.7958078334,126.4441270970);
    var myOptions = {
        zoom: 14,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.SATELLITE
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    var ctaLayer = new google.maps.KmlLayer('http://MYSITES/kml/101.kml');
    ctaLayer.setMap(map);
  }

In Chrome Google Map Placemark shown with blue ballons.

In Google Earth Placemark shown with just name.

These screenshot base on same KML file.

How to show only name with Google Maps in Browser??


回答1:


I've never used it, but there is a library to show labels on a marker. If you used a transparent marker with a label you may get the desired outcome.

MarkerWithLabel

If that doesn't work, I used to create custom labels for markers using an OverlayView.

Create marker with custom labels in Google Maps API v3

This would be an alternative to using KML Layers I guess.




回答2:


There is no implemented method to show anything else than an image there.

So 1 option could be: use the iconStyle to put there the name(an image that contains the name, this may be created by a serverside script that accepts parameters, so they don't need to be static).

Another option(using the Maps-JS-API): Instead of showing the KML-layer, parse the layer on your own and create custom overlays with the names.



来源:https://stackoverflow.com/questions/14330211/google-maps-javascript-api-v3-how-to-placemark-show-name-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!