Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

google maps - How to add KMZ file in drupal 7?

I have got KMZ file and I don't know how to show it from drupal. So, I research and found those codes.

function CoverageMap() {

  var map = new google.maps.Map(document.getElementById('coverageMap'), {
    zoom: 15,
    center: {lat: 16.800915763233845, lng: 96.1567211141123}
   });

   var kmzLayer = new google.maps.KmlLayer('http://test.dev/sites/all/themes/bootstrap_business/coverage/ygn_mdy.kmz');
   kmzLayer.setMap(map);

}

I put this code and save the file Coverage.js.
But, the file location is static location and I would like to change dynamic because the location will not be like this when I upload the file in server.
Can I put this code <?php echo base_path().path_to_theme() ?>/coverage/ygn_mdy.kmz
Should KMZ file put like this as an offline or is there other ways?
Please help me to solve this problem. I've been trying to find this since 2wks ago.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I believe having a dynamic path for your KMLs is not a problem as long as you place them in the correct file. Adding <?php echo base_path().path_to_theme() ?> into a javascript file Coverage.js will likely wont work because it will just be treated as an ordinary string.

I would suggest all the javascript codes that there's a PHP involvement should be saved in a PHP file. In your case, saving it to something like Coverage.php and the code should look something like this:

function CoverageMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 11,
      center: {lat: 16.800915763233845, lng: 96.1567211141123 }
  });
  var kmzLayer = new google.maps.KmlLayer("<?php echo $base_path().$path_to_theme().'/coverage/ygn_mdy.kmz'; ?>");
  kmzLayer.setMap(map);
}

Check Google Maps Javascript API KML Layers to learn more. You can also check Displaying KML to learn more on displaying information of a KML file.

Hope this helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...