Map: vii.path.berkeley.edu/portal/eric/index200.php
JavaScript: vii.path.berkeley.edu/portal/eric/map_functions.js
XML Markers: vii.path.berkeley.edu/portal/eric/data.xml
retrieveMarkers PHP and storeMarkers PHP included after the
description of the problem.
*****************
My apologies if this has been covered elsewhere but I have been
searching for some time and haven't found a solution to this simple
problem.
I have a map with marker data in an XML file in the root directory.
I've got the map loading and displaying the markers from the XML file
using the retrieveMarkers() JavaScript function in the
map_functions200.js file.
Users can click the map to add a marker at the lat and long that they
clicked. This is done through the storeMarker() JavaScript function in
the same .js file.
My problem is that I need users to be able to remove markers from the
map (though a button on the marker's info window, which opens when the
marker is clicked). I've explored a couple of options for doing this
but haven't found success with either of them:
1. Searching the lat and long attributes of all XML <marker> elements
for matches to the lat or long of the most recently clicked marker,
and then deleting that XML <marker> element using PHP (it's easy to
store the lat and long of the most recently clicked marker in global
JavaScript variables).
2. Loading all of the markers from the XML file into a JavaScript
array and adding and removing markers from that array (which could be
more straightforward) and then saving the contents of that array back
into the XML file at the end of the session.
I would appreciate any guidance in this problem, or critiques of what
I've done so far as I am a real amateur at this. Am I taking the best
approach here? It seems like this should be a common, straightforward
thing to do.
*****************
retrieveMarkers.php:
<?php
header('Content-Type: text/xml;charset=UTF-8');
$markers = file_get_contents('data.xml');
echo <<<XML
<markers>
$markers
</markers>
XML;
?>
storeMarker.php:
<?php
header('Content-Type: text/xml;charset=UTF-8');
$lat = (float)$_GET['lat'];
$lng = (float)$_GET['lng'];
$comment = htmlspecialchars(strip_tags(utf8_encode($_GET
['comment'])));
//Create an XML node
$marker = <<<MARKER
<marker lat="$lat" lng="$lng" comment="$comment"/>
MARKER;
//open the data.xml file for appending
$...@fopen('data.xml', 'a+');
if(!$f) die('<?xml version="1.0"?>
<response type="error"><![CDATA[Could not open data.xml file]]></
response>
');
//add the node
$...@fwrite($f, $marker);
if(!$w) die('<?xml version="1.0"?>
<response type="error"><![CDATA[Could not write to data.xml file]]></
response>');
@fclose($f);
//return a response
$newMarkerContent = "<div>$comment</div><br/><div><button type=\"button
\" onclick=\"deleteMarker()\">Remove marker</button></div>";
echo <<<XML
<?xml version="1.0"?>
<response type="success" icon="$icon"><![CDATA[$newMarkerContent]]></
response>
XML;
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---