bwakad Posted March 29, 2014 Share Posted March 29, 2014 Page-Template code: $address = $page->select_province->title.' '.$page->select_city->title; $address = urlencode($address); $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$address."&sensor=true"; $xml = simplexml_load_file($request_url) or die("url not loading"); $status = $xml->status; if ($status=="OK") { $Lat = $xml->result->geometry->location->lat; $Lon = $xml->result->geometry->location->lng; $Location = "$Lat,$Lon"; echo $Location; // here I get back latitude, longitude which are exactly right... } >>> error here <<< $map = $modules->get('MarkupGoogleMap'); echo $map->render($Location,'location_map'); ps. I don't know how to get those two fields in the $address in a short way... // and the error says: Error: Call to a member function first() on a non-object line 175 from MarkupGoogleMap.module $marker = $pageArray->first()->get($fieldName); The only thing I could find on internet was it has something to do with a name not in DB, but I really need some more explenation... I suspect it to be $marker versus $Location... can anyone tell me??? Link to comment Share on other sites More sharing options...
adrian Posted March 29, 2014 Share Posted March 29, 2014 In the docs for this module it says: In the location where you want to output your map, place the following in your template file: $map = $modules->get('MarkupGoogleMap'); echo $map->render($page, 'map'); You are using $Location there which is a string "$Lat, $Lon" based on your definition of it. It needs to be a page object. When you are getting errors like this, it is sometime best to start with the default code from the docs before experimenting with other approaches, like parsing xml. Stick with the basics. Once you have those grasped, the rest will be easier to sort out and we'll continue to help/ Link to comment Share on other sites More sharing options...
bwakad Posted March 29, 2014 Author Share Posted March 29, 2014 Thanks, I already rolled back to the basics - and on the other side still making some neat changes on skyscrapers (other vhost). I did not fully understand the render - what exactly does it do, from the description it does not tell me. It is used often in templates, but it states to do markup by yourself: A relevant example in this case is the MarkupPageArray plugin module, which is installed by default and adds a render() function to all fields that return a PageArray (as many functions in ProcessWire do). So a shortcut to the above example could be: <?php echo $page->children->render(); ?> In most cases, I recommend that you generate the markup yourself rather than using plugins to do it for you... especially when getting started. That way you will get a better understanding of the API and more control over your markup. Link to comment Share on other sites More sharing options...
cstevensjr Posted March 29, 2014 Share Posted March 29, 2014 https://processwire.com/talk/topic/1102-to-render-or-not-to-render-thats-the-question/ 2 Link to comment Share on other sites More sharing options...
bwakad Posted March 30, 2014 Author Share Posted March 30, 2014 Ahaaaa.... so render can be used to give output a different look if you wanted Link to comment Share on other sites More sharing options...
Martijn Geerts Posted March 30, 2014 Share Posted March 30, 2014 ->render() is just a methode in a class (function), and output mostly the expected thing/string. The name render is called render cause thats a good english word for rendering. You're free to use render() as methode name while developing. You could swop the name render for bwaked, if you think it's more appropriate for the thing you're writing or want to output. And if your render methode wil throw an exception, you'll get a different look 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