bernhard Posted June 13, 2015 Share Posted June 13, 2015 hi peter, the documentation of mapmarker states: markerLinkField Page field to use for the marker link, or blank to not link (type: string; default: url). so you could define any URL in an extra URL or TEXT field in your pagetable item. you could also set this field to hidden and populate it via hook to ##parent## and then replace all occurrences of ##parent## with any url like this: i tried it with a single TEXT-field called "markerlink" and put in ##parent## manually and the marker was linked correctly to the current page parent ($page->parent->url) $map = $modules->get('MarkupGoogleMap'); $content = str_replace("##parent##", $page->parent->url, $map->render($page->maptable, 'map', array('markerLinkField' => 'markerlink'))); edit: seems you updated your post i think there are also modules that populate the value of a given field to specific values? you could also use such tools to populate the "markerlink" field automatically and you then would only have to define this field to be used via mapmarker as link: $options = array('markerLinkField' => 'your_field_with_the_url_you_want'); Link to comment Share on other sites More sharing options...
Peter Knight Posted June 13, 2015 Share Posted June 13, 2015 Yes, I updated my post. I didn't want to create another post and monopolise the thread I don't really follow your instructions but that's me wrapping my head around this and not your instructions. basically, I didn't realise that url below could be the name of a field on my PageTable page. 'markerLinkField' => 'url' Based on this, you saying I can create a field called url and somewhow reference the parent page address in that? And by the way, the map I am referring to would be a map displaying ALL pins right across the site and not just pins associated with a single page. Link to comment Share on other sites More sharing options...
bernhard Posted June 13, 2015 Share Posted June 13, 2015 yes, in your example "url" would be a FIELD in your pagetable. for example: template "map" field: title field: maptable (type pagetable with items having template "maptableitems") template "maptableitems" field: title field: map (type mapmarker) field: markerurl (type text or url) then just use this settings: $map = $modules->get('MarkupGoogleMap'); $content = $map->render($page->maptable, 'map', array('markerLinkField' => 'markerurl')); ...and the marker would have no link (blank) or the link that you specify in your "markerurl" field. try it manually first. you then could set "markerurl" dynamically via hook or a seperate plugin. i think lostkobrakai made something that could fit here... please google or wait for his advice Link to comment Share on other sites More sharing options...
Peter Knight Posted June 13, 2015 Share Posted June 13, 2015 Ok, I understand the logic so thanks for clarifying. I still think my Map Overview page possibly has a different setting as it's pulling in points not from it's own PageTable children (it doesn't have any) but from all other pages with PageTable children. So it's more like this (without any working urls <?php $items = $pages->find("template=update-location, pt_map!='', sort=title"); $map = $modules->get('MarkupGoogleMap'); echo $map->render($items, 'pt_map', array( 'height' => '500px', 'useHoverBox' => true ) ); ?> Anyway, thanks for all the help. much appreciated. What I've done for the moment is to add a manual session redirect on my pagetable child page templates. <?php $session->redirect($page->parent->url); ?> It's probably not great for SEO reasons but it'll help me press ahead for the moment. Link to comment Share on other sites More sharing options...
bernhard Posted June 13, 2015 Share Posted June 13, 2015 i thought about this but didn't want to recommend it i still don't get what's wrong with changing this $items = $pages->find("template=update-location, pt_map!='', sort=title"); to that $items = $page->maptable; your selector gets all pages with template "update-location" where pt_map is not blank, so no wonder that it shows all locations from every page in your website! edit: of course "maptable" has to be changed to the name of your pagetable field Link to comment Share on other sites More sharing options...
naldrocks98 Posted June 24, 2015 Share Posted June 24, 2015 nice Link to comment Share on other sites More sharing options...
naldrocks98 Posted June 24, 2015 Share Posted June 24, 2015 nice Link to comment Share on other sites More sharing options...
sgt.blikey Posted July 20, 2015 Share Posted July 20, 2015 I am having a problem returning values for 'lat' and 'lng', which evaluate to '0.000000' when called in my page's template file. I have a field, 'map', of type MapMarker. The default address is filled out and the corresponding Latitude and Longitude values are populated. The field is included in a template, 'contact-us' and this template is used by a page, 'Contact Us'. In the admin, editing the 'Contact Us' page I see the subfields of my 'map' field are populated correctly and a map is displayed, with a pin dropped in the correct place. I have reduced the contents of contact-us.php to the following: <?php if ($page->map) { echo ("Address: {$page->map->address}<br />"); echo ("Latitude: {$page->map->lat}<br />"); echo ("Longitude: {$page->map->lng}<br />"); echo ("Zoom: {$page->map->zoom}<br />"); } ?> The output is as follows (I have edited the address): Address: Name of Establishment, Street, Town, Postcode Latitude: 0.000000 Longitude: 0.000000 Zoom: 12 I do not understand, why are 'lat' and 'lng' evaluating as '0.000000'? Thanks, Nic Versions: PW = 2.5.29; FieldTypeMapMarker = 2.0.6; InputfieldMapMarker = 2.0.7; MarkupGoogleMap = 1.0.1 I deleted and recreated the field and this problem went away. 1 Link to comment Share on other sites More sharing options...
Robin S Posted August 7, 2015 Share Posted August 7, 2015 Great module. One thing that's missing from the field setup options is the ability to set the geocode checkbox to "off" by default. The site I'm building requires editors to drop map pins that don't correspond to any street address and I expect they're going to be confused when the address field geocodes to some distant street address. Link to comment Share on other sites More sharing options...
Juergen Posted August 21, 2015 Share Posted August 21, 2015 In the description I read: For example, Google Maps will geocode any of these: 125 E. Court Square, Decatur, GA 30030 Atlanta, GA Disney World but is it normal that it changes the entered address after geocoding to a certain format?? In my case it changes Plus-Kauf-Straße 1, 4061 Pasching, Oberösterreich, Österreich to Plus-Kauf-Straße 1, 4061, Österreich after pressing the save button - so it shortened the entered address. This is a problem because I have included a lot of schema.org markup and I have created an array from the whole address, where I can pick up the different parts of the address separately. If the address is in another format I run into problems. So this is only if geocoding is on. Best regards Link to comment Share on other sites More sharing options...
bernhard Posted August 21, 2015 Share Posted August 21, 2015 hi jürgen, that's standard behaviour of the google maps api. you can see it's response here: https://maps.googleapis.com/maps/api/geocode/json?address=Plus-Kauf-Stra%C3%9Fe%201,%204061%20Pasching,%20Ober%C3%B6sterreich,%20%C3%96sterreich it uses the "formatted_address" field. you could either try to get more information from the json or create a seperate field for the address that is displayed (unshortened). not sure what you mean exactly by the schema.org array single parts or how your setup is exactly... Link to comment Share on other sites More sharing options...
Juergen Posted August 21, 2015 Share Posted August 21, 2015 Hello BernhardB, thanks for your response. not sure what you mean exactly by the schema.org array single parts or how your setup is exactly... I create an array of the address entered in the Google map address field. $location = $page->veranstaltungmap->address;//this is the google map address field $location = explode(",", $location);//cut the address into pieces and create the array //create each part of the address with schema.org markup $street = '<span itemprop="streetAddress">' . $location[0] . '</span>, '; $postalcode = '<span itemprop="postalCode">' . $location[1] . '</span>'; $locality = '<span itemprop="addressLocality">' . $location[2] . '</span>, '; $region = '<span itemprop="addressRegion">' . $location[3] . '</span>, '; $country = '<span itemprop="addressCountry">' . $location[4] . '</span>'; As you can see I added a lot of schema.org markup to the various part of the address. This only works if the address is in the correct syntax (street + number, postal code, locality, region, country). If there is one part missing the schema.org part will not be fitting to the output. I hope it is a little bit clearer now. But you gave me a hint: I could query the google api and take this array and its content for creating schema.org markups. I didnt know that this exist - I hope there are no limitations in the amount of queries!! Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 21, 2015 Share Posted August 21, 2015 I'd really suggest storing this data separate to the map-marker data. In such a situation you don't want to depend on a tool you cannot surely control what data it spits out (changes to the module or the api). 2 Link to comment Share on other sites More sharing options...
bernhard Posted August 22, 2015 Share Posted August 22, 2015 yep, i would also NOT trust this special field value because if the marker is moved it could also completely change the address generated by the google maps api! seperate fields would be the safe way but of course it depends how sensitive your data is... @limits: https://developers.google.com/maps/licensing 1 Link to comment Share on other sites More sharing options...
Juergen Posted August 23, 2015 Share Posted August 23, 2015 I think you are right - I will create fields for that! Thanks Link to comment Share on other sites More sharing options...
theoretic Posted September 8, 2015 Share Posted September 8, 2015 Hi guys! And thanks for a perfect module. I would like to propose a small tweak. Function render() generates some HTML and Javascript. The problem is that the Javascript code implicitly requires JQuery. Here's an example: this.hoverBox = $(markup); If JQuery is not loaded before, this javascript code will generate an error. I propose to wrap the map-generating Javascript into function which executes after the whole document (including the JQuery call) is loaded. Example: window.onload = function(){ /* original MarkupGoogleMap javascript code goes here */ } This tweak should be inserted into original MarkupGoogleMap.module file. Real code example: $out .= "<script type='text/javascript'>" . " window.onload = function(){". "if(typeof google === 'undefined' || typeof google.maps === 'undefined') { " . "alert('MarkupGoogleMap Error: Please add the maps.googleapis.com script in your document head.'); " . "} else { " . "var $id = new MarkupGoogleMap(); " . "$id.setOption('zoom', $zoom); " . "$id.setOption('mapTypeId', google.maps.MapTypeId.$type); " . ($options['icon'] ? "$id.setIcon('$options[icon]'); " : "") . ($options['iconHover'] ? "$id.setIconHover('$options[iconHover]'); " : "") . ($options['shadow'] ? "$id.setShadow('$options[shadow]'); " : "") . ($options['useHoverBox'] ? "$id.setHoverBox('" . str_replace("'", '"', $options['hoverBoxMarkup']) . "');" : "") . $options['init'] . "$id.init('$id', $lat, $lng); "; foreach($pageArray as $page) { $marker = $page->get($fieldName); if(!$marker instanceof MapMarker) continue; if(!$marker->lat) continue; $url = $options['markerLinkField'] ? $page->get($options['markerLinkField']) : ''; $title = $options['markerTitleField'] ? $page->get($options['markerTitleField']) : ''; $out .= "$id.addMarker($marker->lat, $marker->lng, '$url', '$title', ''); "; } if(count($pageArray) > 1 && $options['fitToMarkers']) $out .= "$id.fitToMarkers(); "; $out .= "} } </script>"; Tried this tweak in one of my projects, works like a charm. Link to comment Share on other sites More sharing options...
theoretic Posted September 9, 2015 Share Posted September 9, 2015 deleted Link to comment Share on other sites More sharing options...
regesh Posted September 17, 2015 Share Posted September 17, 2015 Hi all. Cound anybody tell me how to generate map if for items if have not subpages but fieldtype repeater with "map field". So there is no "pages object". found here --> https://processwire.com/talk/topic/9711-map-marker-map/?view=findpost&p=96787 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted September 17, 2015 Share Posted September 17, 2015 @regesh: Repeater items are pages Link to comment Share on other sites More sharing options...
Tom. Posted October 21, 2015 Share Posted October 21, 2015 Hello, I'm struggling with this one, I'm not entirely sure what's happening. I seem to have everything set up correctly as per instructions however I'm getting a javascript error and the map is displaying empty: "Cannot read property 'x' of undefined" However everything looks fine and rendered correctly in the backend FieldType. Not sure if anyone has come across this before? I can use the API for now to render it using $page->location->lat, however using $map->render($page, 'location') doesn't seem to be working. EDIT: S6 1ND (0.000000, 0.000000, 15) For some reason the longitude and latitude is returning 0.000~, 0.000~ even though they are defined in the backend 53.4251316, -1.5238964000000124 EDIT: It seems to be the geolocation longitude that seems to be causing the problem "-1.5238964000000124" though this was generated by the system based on the address. Link to comment Share on other sites More sharing options...
bernhard Posted October 21, 2015 Share Posted October 21, 2015 have you added google maps to your frontend <head>? <script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?sensor=false'></script> if yes: maybe you can show us some code? 1 Link to comment Share on other sites More sharing options...
Tom. Posted October 21, 2015 Share Posted October 21, 2015 have you added google maps to your frontend <head>? <script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?sensor=false'></script> if yes: maybe you can show us some code? Hello, I have indeed. <?php $map = $modules->get('MarkupGoogleMap'); echo $map->render($page, 'location'); ?> It's outputting the map fine when I use any other location but that one. It seems to be a problem with the longitude value. If I use any other location it works fine however if I use "S6 1ND" I get an output of 0.0000, 0.0000 in $page->location. However in the back-end it will have the correct values. Even $page->location->lat will return 0.0000. Can you replicate it? Create a map field and enter the location S6 1ND. EDIT: I deleted and recreated the field and this problem went away. It seems this user had the same problem as me, deleting and recreating the field fixed it. I wonder if it's something to do with the default? Link to comment Share on other sites More sharing options...
bernhard Posted October 22, 2015 Share Posted October 22, 2015 can't replicate it google maps api response is also ok: https://maps.googleapis.com/maps/api/geocode/json?address=S6%201ND 2 Link to comment Share on other sites More sharing options...
Tom. Posted October 22, 2015 Share Posted October 22, 2015 can't replicate it google maps api response is also ok: https://maps.googleapis.com/maps/api/geocode/json?address=S6%201ND 2015-10-22 10_57_10-Edit Page_ Impressum • jvplf.dev.png 2015-10-22 10_56_31-Impressum.png Thanks for your help Bernhard, it seems to have corrected itself deleting and re-adding the field. It must have just been a strange bug. Thank you very much for your response and help, it's much appreciated. 1 Link to comment Share on other sites More sharing options...
bernhard Posted November 6, 2015 Share Posted November 6, 2015 link removed due to restriction of google maps api: Terms of Use Restrictions The Google Maps Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now