• Resolved popsantiago

    (@popsantiago)


    Hello Webaware,

    Can you explain me why my map disappear ?
    https://www-test.comptoirdesentreprises.com/region/haute-normandie/
    I use the KML Dom Generation
    https://www-test.comptoirdesentreprises.com/region/haute-normandie/?feed=kmlregionrss

    I’m not sure about the function…

    <?php
    
    // Creates the Document.
    $dom = new DOMDocument('1.0', 'UTF-8');
    
    // Creates the root KML element and appends it to the root document.
    $node = $dom->createElementNS('https://earth.google.com/kml/2.1', 'kml');
    $parNode = $dom->appendChild($node);
    
    // Creates a KML Document element and append it to the KML element.
    $dnode = $dom->createElement('Document');
    $docNode = $parNode->appendChild($dnode);
    
    // Creates the two Style elements, one for standard and one for bar, and append the elements to the Document element.
    $strdStyleNode = $dom->createElement('Style');
    $strdStyleNode->setAttribute('id', 'standardStyle');
    $strdIconstyleNode = $dom->createElement('IconStyle');
    $strdIconstyleNode->setAttribute('id', 'standardIcon');
    $strdIconNode = $dom->createElement('Icon');
    $strdHref = $dom->createElement('href', 'https://maps.google.com/mapfiles/kml/pal2/icon63.png');
    $strdIconNode->appendChild($strdHref);
    $strdIconstyleNode->appendChild($strdIconNode);
    $strdStyleNode->appendChild($strdIconstyleNode);
    $docNode->appendChild($strdStyleNode);
    
    /*
    $barStyleNode = $dom->createElement('Style');
    $barStyleNode->setAttribute('id', 'barStyle');
    $barIconstyleNode = $dom->createElement('IconStyle');
    $barIconstyleNode->setAttribute('id', 'barIcon');
    $barIconNode = $dom->createElement('Icon');
    $barHref = $dom->createElement('href', 'https://maps.google.com/mapfiles/kml/pal2/icon27.png');
    $barIconNode->appendChild($barHref);
    $barIconstyleNode->appendChild($barIconNode);
    $barStyleNode->appendChild($barIconstyleNode);
    $docNode->appendChild($barStyleNode);
    */
    
    $term_region = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    
        $args = array(
        	'post_type' => 'visite',
        	'posts_per_page' => -1,
        	//'p' => 2028,
        	'post_status' => 'any',
        	'orderby' => 'ASC',
        	'tax_query' => array(
    					array(
    						'taxonomy' => 'tax_region',
    						'field' => 'slug',
    						//'terms' => 'alsace',
    						'terms' => $term_region->slug,
    						)
    					),
    		);
        $posts = new wp_query( $args );
        $posts = $posts->posts;
    
    	//var_dump($posts);
    	//die();
    
    // Iterates through the MySQL results, creating one Placemark for each row.
    foreach( $posts as $post )
    {
        setup_postdata( $post );
        $location = get_post_meta( $post->ID, 'adress_factory_map', true );
        if($location != ''){
    		// Creates a Placemark and append it to the Document.
    
    		$node = $dom->createElement('Placemark');
    		$placeNode = $docNode->appendChild($node);
    
    		// Creates an id attribute and assign it the value of id column.
    		$placeNode->setAttribute('id', 'placemark' . $post->ID);
    
    		// Create name, and description elements and assigns them the values of the name and address columns from the results.
    		$nameNode = $dom->createElement('name',htmlentities($post->post_title));
    		$placeNode->appendChild($nameNode);
    		$descNode = $dom->createElement('description', $location["address"]);
    		$placeNode->appendChild($descNode);
    		//$styleUrl = $dom->createElement('styleUrl', '#' . $row['type'] . 'Style');
    		$styleUrl = $dom->createElement('styleUrl', '#standardStyle');
    		$placeNode->appendChild($styleUrl);
    
    		// Creates a Point element.
    		$pointNode = $dom->createElement('Point');
    		$placeNode->appendChild($pointNode);
    
    		// Creates a coordinates element and gives it the value of the lng and lat columns from the results.
    		$coorStr = $location['lng'] . ','  . $location['lat'];
    		$coorNode = $dom->createElement('coordinates', $coorStr);
    		$pointNode->appendChild($coorNode);
      	}
    }
    
    $kmlOutput = $dom->saveXML();
    header('Content-type: application/vnd.google-earth.kml+xml');
    echo $kmlOutput;
    ?>

    Thank you.

    https://www.ads-software.com/plugins/wp-flexible-map/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter popsantiago

    (@popsantiago)

    Hello,

    I found my bug…

    A “space” in the call feed function =/

    Thanks

    Thread Starter popsantiago

    (@popsantiago)

    Hum…

    I really don’t understand…

    Works for a “region” but not for the ohters…
    Ex:
    work : https://www-test.comptoirdesentreprises.com/region/centre/
    doesn’t work : https://www-test.comptoirdesentreprises.com/region/franche-comte/

    Plugin Author webaware

    (@webaware)

    G’day popsantiago,

    I can see a map on both those pages. The markers are in the middle of the Atlantic Ocean ?? but there’s a map on both pages. Can you describe your problem in more detail please?

    cheers,
    Ross

    Thread Starter popsantiago

    (@popsantiago)

    Hello,

    thanks for reply.

    For sure i see the map ??
    But i don’t see the markers (on my screen…if you see Calgary Board is just default center of map)… should be on France region…

    And now the ‘centre’ page doesn’t work anymore…

    It seems kml is not use to generate the markers…

    … I really hate cache !!! I just try to donwload the kml file… and now is Non-Valide !
    I fix it,

    ?feed=kmlregionrss download the kml

    I don’t really know if i’m more clear :-/

    Thanks

    Plugin Author webaware

    (@webaware)

    Your KML has &eacute; entities in it; that’s HTML, not XML. Google Maps is barfing on those entities. Probably part of your content from which you’re generating the KML files. Replace with é and you’ll be OK.

    cheers,
    Ross

    Thread Starter popsantiago

    (@popsantiago)

    OK !!!

    Like every time Shoot head !!!

    Really really thank you Ross !!!

    That’s done and fix.

    See you (i hope not too early ?? )

    Pop

    Plugin Author webaware

    (@webaware)

    No worries, glad it was that simple.

    I recommend you check out XMLWriter sometime. It’s much more succinct than DOMDocument, and also allows you to build XML directly to the output stream:

    header('Content-type: application/vnd.google-earth.kml+xml');
    $xml =new XMLWriter();
    $xml->openURI('php://output');

    cheers,
    Ross

    Thread Starter popsantiago

    (@popsantiago)

    Hey Ross,

    Do you think this kind of function can make some trouble to my .htaccess file ? =/

    Because i don’t know if it’s normal but the .htaccess is modified each minutes…
    And sometimes the file break my website Internal Servor Error 500…
    when the file is totally destroy…

    Thanks

    Plugin Author webaware

    (@webaware)

    G’day Pop,

    That sounds like a “security” plugin, probably adding IP addresses to a blacklist. Those things suck, I tend to just install a login limit plugin and some custom .htaccess rules.

    cheers,
    Ross

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Change Theme & KML generator’ is closed to new replies.