Monday, 15 June 2015

javascript - downloadUrl function not working for creating google map locator with opencart -



javascript - downloadUrl function not working for creating google map locator with opencart -

i using opencart develop http://www.goskitz.com.au/index.php?route=information/dealers

in dealers.php file there function called query() search postcodes database store locations results , outputted xml format. example, if typed 3000 , select melbourne, xml output be:

function query(): public function query(){ // query coding part removed // output xml $dom = new domdocument("1.0"); $node = $dom->createelement("markers"); $parnode = $dom->appendchild($node); header("content-type: text/xml"); // iterate through rows, adding xml nodes each foreach($result $key => $li){ // add together xml document node $node = $dom->createelement("marker"); $newnode = $parnode->appendchild($node); $newnode->setattribute("name",$li['name']); $newnode->setattribute("address", $li['address']); $newnode->setattribute("lat", $li['lat']); $newnode->setattribute("lng", $li['lng']); $newnode->setattribute("distance", $li['distance']); } echo $dom->savexml(); } } output <markers><marker name="harvey norman big buys" address="shop 9&amp;11 ground level springvale homemaker centre 917 princes highway springval vic 3171" lat="-37.927456" lng="145.143845" distance="19.74128375361586"></marker>....blahblah... <markers>

then found downloadurl function not working, no matter url put, nil happens. why happen?

any thought grateful.

i have paste javascript in http://pastebin.com/yu0bx3vz

the piece of code showing here responsible generation of xml. generated xml contains marker data, needs parsed , handed on google maps api, in order draw markers.

the first thing might want is, 1 marker working, level multiple markers. seek xml right , marker(s) drawn on map. map must initialized before seek add together marker(s).

if works out, proceed load marker xml dynamically via jquery. because working jquery, suggest drop downloadurl() function, in favor of simple jquery ajax .get() request added success function, parsing incomming response xml.

$(document).ready(function() { $.ajax({ type: "get", url: "markers.xml", // xml source: either static xml file or xml generated php datatype: "xml", success: parsexml // parse marker xml }); }); // thought is: xml -> var "location" -> addmarker(location) function parsexml(xml) { // foreach marker extract xml info (lat,long,...) $(xml).find("marker").each(function(index){ // , assign new location var var location.lat = $(this).find('lat').text(); var location.long = $(this).find('long').text(); var location.name = $(this).find('name').text(); // utilize info add together marker addmarker(location); ) } function addmarker(location) { // marker "point" on map defined it's lat/long var point = new google.maps.latlng(location.lat, location.lng); var marker = new google.maps.marker({ position:point, map: map, title: location.name }); };

if need bind info window or something, pops up, when clicked on marker icon, please search bindinfowindow() in article https://developers.google.com/maps/articles/phpsqlajax_v3

i think, origin of downloadurl() function got, in tutorial, don't utilize jquery, do.

this question might of help too: loading xml via jquery google maps api v3

javascript php jquery google-maps google-maps-markers

No comments:

Post a Comment