google maps in laravel project - php

I am workin on laravel project in which i have to integrate google maps. I am using this package https://github.com/alexpechkarev/google-maps for google maps . I install this package and get api key from https://console.developers.google.com/apis/credentials . then I just follow the usage of this package for example i write the code in my controller
$response = \GoogleMaps::load('geocoding')
->setParam (['address' =>'santa cruz'])
->get();
It giving me data in json encode formate but i dont't know what i do next . How can i display maps . can someone please give me proper example of this package via code i will be thankfull for that thanks in advanced

You need to actually implement the map on the front end in your views:
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js" async defer></script>
<script>
function initMap() {}
</script>
Read this: https://developers.google.com/maps/tutorials/fundamentals/adding-a-google-map#introduction

Related

How to use PHP with Composition API VueJS 3

Coming from a PHP/jQuery background, where you can have PHP and jQuery code in the same file, for example some file called index.php:
<?php
echo "hey";
?>
<script>
$("#someId").html("abc")
</script>
How can you do something similar with the Composition API in VueJS v3 where you can access access your PHP variables/sessions etc. inside of a .vue file or have your SFC files to include PHP code as well?
I know you can do this by including the vue framework with script tags inside of your index.php file but as far as I'm aware you can't use the Composition API with this method.
I'm probably missing something basic but I haven't been able to find the answer.

How to access google map through google map API in codeigniter

I Have downloaded the google map library from GitHub and added it in to my libraries in Codigniter. After that I have loaded this library to the controller:
$this->load->library('googlemaps');
and then:
$this->googlemaps->initialize();
$data['map'] = $this->googlemaps->create_map();
After that I have added this in my view:
<?php echo $map['js']; ?>
<?php echo $map['html']; ?>
But something is wrong when I am trying to access the Google Map.
Can anyone help me?

How to format app engine yaml file for referencing google maps external javascript file

I have a php file, a part of which echos out some html and javascript including an src tag for a google maps api script. In an ordinary php environment this works ok and places the google map into the page. With the app engine when I use the launcher to view the result the explanation mark shows up and doesn't allow me to view the page. There are no problems when I don't try to echo out any javascript so I know the formatting of the yaml file is the problem.
In short I have no idea how to format the yaml file for this situation.
Like so..
echo '
<html>
<head>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false"></script>
</head>
<body>
<div id="map" style="width: 900px; height: 700px">
</div>
etc...
'; // end echo
Reading the app engine documentation on yaml files it's not clear to me whether or not it's possible to echo out urls via an src when using app engine. All the notes I've read seem to indicate that the scripts have to go in a separate static directory within the yaml folder but how do I just refer to a javascript file url on another server ?
The documentation seems incredibly complicated for what previously was simply a matter of echoing the javascript. I've lost track of the number of variations that I've made to the yaml file to get it to conform to the way I'm supposed to format it but i cant find any clear instructions on how to do it.
Could somebody who knows about this please give me some guidance. I'd be really grateful.

mixpanel analytic in wordpress blog not working

I am trying to use mixpanel for analytic in my Wordpress blog (just for learning).
My blog is all php.
I got the code from mixpanel's website and put it in my header.php file.
<!-- start Mixpanel --><script type="text/javascript">(function(c,a){window.mixpanel=a;var b,d,h,e;b=c.createElement("script");b.type="text/javascript";b.async=!0;b.src=("https:"===c.location.protocol?"https:":"http:")+'//cdn.mxpnl.com/libs/mixpanel-2.0.min.js';d=c.getElementsByTagName("script")[0];d.parentNode.insertBefore(b,d);a._i=[];a.init=function(b,c,f){function d(a,b){var c=b.split(".");2==c.length&&(a=a[c[0]],b=c[1]);a[b]=function(){a.push([b].concat(Array.prototype.slice.call(arguments,0)))}}var g=a;"undefined"!==
typeof f?g=a[f]=[]:f="mixpanel";g.people=g.people||[];h="disable track track_pageview track_links track_forms register register_once unregister identify name_tag set_config people.set people.increment".split(" ");for(e=0;e<h.length;e++)d(g,h[e]);a._i.push([b,c,f])};a.__SV=1.1})(document,window.mixpanel||[]);
mixpanel.init("MYKEY");</script><!-- end Mixpanel -->
Here, MYKEY is my actual key.
Now, I want to see page views for each of my blog posts.
I am putting following code in page.php, which gets called each time a post is viewed (afaik).
<script type="php">
mixpanel.track("Viewed Post")
</script>
But I am not getting any data back. Can someone please help me here?
I am using Mixpanel on my blog (along Google Analytics). Some suggestions
Make sure you've put the mixpanel code before the head closing statement </head>. In many themes you will find a lot of code below the </head> for example the <body class="<?php hybrid_body_class(); ?>"> in the case of hybrid based themes
I am not sure why you are using <script type="php"> the usual is <script type="text/javascript">
Hope this helps!
in all my wordpress website i want to delete this mixpanel, someone can tell me how i can do that?
MixPanel does not work well with Wordpress blog. I would use Google Analytics.

RegisterPackage depends on RegisterScriptFile

I have a package that requires Google Map library. And I implemented it like this in the view.
<?php Yii::app()->clientScript->registerScriptFile('http://maps.googleapis.com/maps/api/js?sensor=false&language=' . Yii::app()->language . '&region='.Yii::app()->language, CClientScript::POS_HEAD); ?>
<?php Yii::app()->clientScript->registerPackage('somelibrary'); ?>
(Note that the Google Map library needs a parameter Yii::app()->language).
But in the output, the package is always placed above the google maps.
<script type="text/javascript" src="/project/assets/74e60422/somelibrary.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&language=id&region=id"></script>
Is there any solution to make the Google Maps library as the package dependency? Or, at least, how to place the somelibrary package right after (not far below) the google maps ?
You can make the google map script a package itself by configuring the packages property of CClientScript.
Then you can add the googlemap to your packages dependencies by configuring 'depends' in the package configuration. This should then add the scripts in the correct order.
To add a package you can do the following (didn't try that, but should work):
Yii::app()->clientScript->addPackage('googleMap', array(
'baseUrl'=>'http://maps.googleapis.com/maps/api',
'js'=>array('js?sensor=false&language=' . Yii::app()->language . '&region='.Yii::app()->language)
));
Same 'googleMap'=>array(/*...*/) will work when you put it in your configuration.
registerPackage() method don't have the any option to decide its position but you can decide position of registerScriptfile() like this ...
public CClientScript registerScript(string $id, string $script, integer $position=4)
$position integer the position of the JavaScript code. Valid values include the following:
CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.
CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.
CClientScript::POS_END : the script is inserted at the end of the body section.
CClientScript::POS_LOAD : the script is inserted in the window.onload() function.
CClientScript::POS_READY : the script is inserted in the jQuery's ready function.

Categories