Jump to content

Need a Google Maps Expert


ryan
 Share

Recommended Posts

I'm having trouble understanding if http://www.synbiopro...ap/marker/3210/ leads to an actual page in PW or if it's just a URL that generates the code on the fly... makes sense?

It's using URL segments, where the number (id) is the URL segment. Here's the code from that template if it helps: 

<?php
$id = (int) $input->urlSegment1;
if($id < 1) throw new Wire404Exception();
$marker = $pages->get("template=map-item, id=$id");
if(!$marker->id) throw new Wire404Exception();
echo $marker->render();

That $marker Page is a page using template map-item. The map-item template contains the fields for each map marker item like location/coordinates, categories and notes. The implementation of the template file is just to output a <div> with that info in it, and that's what gets sent through that $marker->render() call above, which goes straight through ajax. 

It's not technically necessary to do it this way, but it does enable us to just pass through an ID on the front-end, since the full URLs take up more space without offering any real benefit in this case. So it's just more efficient to route through a known, consistent URL with an ID appended to it. 

  • Like 1
Link to comment
Share on other sites

Thanks Ryan

Got it working (as seen here on this dev site: http://178.79.146.18/en/projects/).

Thanks also to Adrian for the: $useWrappers = false;

In the RCDMap.js I want to set the correct language

$.get('/en/marker/' + marker.rcdID + '/', {}, function(data) {

Any ideas how I can use a conditional like this inside the .js file?:

if($user->language->title == 'no'){
}else{
}

I know that I can load different .js files for each language like this:

if($user->language->title == 'no'){
echo "<script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=false&language=no'></script>";
}else{
echo "<script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=false'></script>";	
}
Link to comment
Share on other sites

Any ideas how I can use a conditional like this inside the .js file?:

if($user->language->title == 'no'){
}else{
}

I would add a JS object to the page in your <head> tag, from your template file. For example:

<script type="text/javascript">
var user = {};
user.lang = "<?php echo $user->language->title ?>";
</script>

Here, I have specified that user is an empty object, and setting the "lang" property of it to the value from PHP $user->language->title. This way also allows you to add other properties to this should you wish to use more user attributes in the future.

You can then access it from javascript as any other object/variable:

if (user.lang == "no") {
    // one thing
} else {
    // another
}
  • Like 1
Link to comment
Share on other sites

Thanks Craig,

Works great:

echo "<script type='text/javascript'>".
     "var user = {};".
     "user.lang = '{$user->language->title}';".
     "</script>";
...

$.get('/' + user.lang + '/marker/' + marker.rcdID + '/', {}, function(data) {
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...