jquery - Getting a GET error when adding a google map from database values -


using tutorial, trying pull data wordpress custom post type meta box xml file, create google map markers setup database values.

i added folder , file the themes dir called map/generatemapxml.php

generatemapxml.php

<?php  // create xml doc map // start xml file, create parent node $dom = new domdocument("1.0"); $node = $dom->createelement("markers"); $parnode = $dom->appendchild($node);   header("content-type: text/xml");    //query artist info & coordinates. $args = array( 'post_type' => 'artists', 'posts_per_page' => -1 ); $query = new wp_query($args); if($query->have_posts()): ?> <?php while($query->have_posts()): ?>     <?php $query->the_post() ?>     <?php         $mapname    = get_the_title();         $mapaddress = rwmb_meta('artists_location');         $maplat     = rwmb_meta('artists_lat');          $maplong    = rwmb_meta('artists_long');         $maptype    = rwmb_meta('artists_type');          $node = $dom->createelement("marker");         $newnode = $parnode->appendchild($node);            $newnode->setattribute("name",$mapname);         $newnode->setattribute("address",$mapaddress);           $newnode->setattribute("lat",$maplat);           $newnode->setattribute("lng",$maplong);           $newnode->setattribute("type",$maptype);     ?> <?php endwhile ?> <?php endif ?>  <?php echo $dom->savexml(); ?> 

so far good. output proper xml, when try pull file contents jquery per tutorial instructions:

downloadurl("<?php echo get_template_directory_uri(); ?>/map/generatemapxml.php", function(data) {                 var xml = data.responsexml;                 var markers = xml.documentelement.getelementsbytagname("marker");                 (var = 0; < markers.length; i++) {                   var name = markers[i].getattribute("name");                   var address = markers[i].getattribute("address");                   var type = markers[i].getattribute("type");                   var point = new google.maps.latlng(                       parsefloat(markers[i].getattribute("lat")),                       parsefloat(markers[i].getattribute("lng")));                   var html = "<b>" + name + "</b> <br/>" + address;                   var icon = customicons[type] || {};                   var marker = new google.maps.marker({                     map: map,                     position: point,                     icon: icon.icon,                     shadow: icon.shadow                   });                   bindinfowindow(marker, map, infowindow, html);                 }               });             } function downloadurl(url, callback) {           var request = window.activexobject ?               new activexobject('microsoft.xmlhttp') :               new xmlhttprequest;            request.onreadystatechange = function() {             if (request.readystate == 4) {               request.onreadystatechange = donothing;               callback(request, request.status);             }           };            request.open('get', url, true);           request.send(null);         } 

i 500 internal server error:

get http://localhost/test/number/wp-content/themes/testtheme/map/generatemapxml.php 500 (internal server error) localhost/test/number/:93 downloadurl localhost/test/number/:93 load localhost/test/number/:49 onload 

it's if file not there. had chmod settings of folder , file 777. error because of wordpress, or syntax error in code? or quite possible, there easier way of creating map?

went different route on this. works well.

<?php wp_reset_postdata();  $args = array(     'post_type' => 'artists',     'posts_per_page' => -1 ); $query = new wp_query($args); ?> <script>     var infowindow;     var gmarkers = [];     var side_bar_html = "";      (function () {        google.maps.map.prototype.markers = new array();        google.maps.map.prototype.addmarker = function(marker) {         this.markers[this.markers.length] = marker;       };        google.maps.map.prototype.getmarkers = function() {         return this.markers       };        google.maps.map.prototype.clearmarkers = function() {         if(infowindow) {           infowindow.close();         }          for(var i=0; i<this.markers.length; i++){           this.markers[i].set_map(null);         }       };     })();  function mapload() {     var latlng = new google.maps.latlng(40.734673, -73.990602);     var myoptions = {       zoom: 15,       center: latlng,       maptypeid: google.maps.maptypeid.roadmap       //maptypeid: google.maps.maptypeid.satellite     };     map = new google.maps.map(document.getelementbyid("map"), myoptions);     var = new array();              <?php if($query->have_posts()): ?>                 <?php $arraycount = 0 ?>                 <?php while($query->have_posts()): ?>                     <?php $query->the_post() ?>                     <?php                         $mapname   = "";                         $mapnames  = rwmb_meta('aiop_artists_name');                         $namecount = count($mapnames);                         $i = 1;                         foreach($mapnames $name) {                             if(strpos($name,',') !== false) {                                 $fullname = explode(",", $name);                                 if($namecount > 1) {                                     $mapname .= $fullname[1]." ".$fullname[0];                                     if($i != $namecount) {                                         $mapname .= ", ";                                     }                                 } else {                                     $mapname .= $fullname[1]." ".$fullname[0];                                 }                             } else {                                 $mapname = $name;                             }                             $i++;                         }                         $mapimage   = get_the_post_thumbnail(get_the_id(), 'thumbnail', array('class' => 'mapimage'));                         $maptitle   = rwmb_meta('aiop_artists_project_title');                         $mapaddress = rwmb_meta('aiop_artists_location');                         $maplat     = rwmb_meta('aiop_artists_lat');                          $maplong    = rwmb_meta('aiop_artists_long');                         $maptype    = rwmb_meta('aiop_artists_type');                          $maptitle  = str_replace("'", '&#39;', $maptitle);                         $maptitle  = str_replace('"', '&#34;', $maptitle);                          if($maplat != null && $maplat != "" && $maplong != null && $maplong != ""): ?>                             <?php echo "                                 var t =  new object();                                 t.name = '".$mapname."';                                 t.lat =  ".$maplat.";                                 t.lng =  ".$maplong.";                                 mapimage = '".$mapimage."';                                 maptitle = '".$maptitle."';                                 t.info = mapimage+'<p class=map_artistname>'+t.name+'</p><p class=map_artisttitle>'+maptitle+'</p>';                                 a[".$arraycount."] = t;"; ?>                                 <?php $arraycount++ ?>                         <?php endif ?>                 <?php endwhile ?>             <?php endif ?>     (var = 0; < a.length; i++) {         var latlng = new google.maps.latlng(a[i].lat, a[i].lng);         map.addmarker(createmarker(a[i].info,latlng));      } }  function createmarker(name, latlng) {     var marker = new google.maps.marker({             position: latlng,              map: map,          });     google.maps.event.addlistener(marker, "click", function() {       if (infowindow) infowindow.close();       infowindow = new google.maps.infowindow({content: name});       infowindow.open(map, marker);     });     // save info need use later side_bar     gmarkers.push(marker);     // add line side_bar html     side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + '<\/a><br>';     return marker; }  // function picks click , opens corresponding info window function myclick(i) {   google.maps.event.trigger(gmarkers[i], "click"); } </script> 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -