<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaScript Tutorial: Learn JavaScript For Free | Atcodex</title>
	<atom:link href="https://atcodex.com/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://atcodex.com/javascript/</link>
	<description>Achieve financial success without sacrificing well-being! AtCodex provides actionable strategies for managing money, time, and personal growth—all in one place.</description>
	<lastBuildDate>Sat, 28 Aug 2021 17:15:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://atcodex.com/wp-content/uploads/2020/05/cropped-New-Project-1-32x32.png</url>
	<title>JavaScript Tutorial: Learn JavaScript For Free | Atcodex</title>
	<link>https://atcodex.com/javascript/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Remove multiple elements from an array in Javascript/jQuery</title>
		<link>https://atcodex.com/php/remove-multiple-elements-from-an-array-in-javascript-jquery/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Mon, 28 Sep 2020 17:31:11 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Lodash]]></category>
		<category><![CDATA[Underscore]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=1045</guid>

					<description><![CDATA[<p>In this post, we will learn how to Remove multiple elements from an array using Javascript or jQuery give with an example. We can simply remove elements from an array &#8230; </p>
<p>The post <a href="https://atcodex.com/php/remove-multiple-elements-from-an-array-in-javascript-jquery/">Remove multiple elements from an array in Javascript/jQuery</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In this post, we will learn how to Remove multiple elements from an array using Javascript or jQuery give with an example. We can simply remove elements from an array using javascript. Below in the post, we have tried different methods to do the same.</p>



<p class="wp-block-paragraph">Let&#8217;s suppose we have an array in which and we want to remove some particular element from the array without refreshing the page.  In that case, we have to use javascript and jquery to remove the element from the array. Because if we go for server-side language then we have to refresh the page or need to get done the same thing with the help of AJAX and backend language. Which is a kind of long and boring task to do. We can simply use javascript, jquery, and some of the other javascript libraries to do it.</p>



<p class="wp-block-paragraph">Following are the some example we are providing to make you  understand about the topic.</p>



<h2 class="wp-block-heading">Remove element using Vanilla JavaScript</h2>



<p class="wp-block-paragraph">In first, let&#8217;s remove the element using simple javascript and jquery, In this, we will use Array.prototype.remove, grep() and inArray() to remove multiple as well as the duplicate value from the array in jquery. However, you can check <a href="https://atcodex.com/how-to/how-to-remove-duplicate-values-from-an-array-in-php/" target="_blank" rel="noreferrer noopener">How to remove duplicate values from an array in PHP</a></p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;!DOCTYPE html>
&lt;html>
&lt;head>
   &lt;title>Jquery Remove Multiple Values from Array Example&lt;/title>
   &lt;script src="https://code.jquery.com/jquery-1.12.4.js">&lt;/script>
&lt;/head>
&lt;body>
  
&lt;script type="text/javascript">
    var sites = [ "website1.com", "website2.com", "website3.com", "website4.com" ];
  
    Array.prototype.remove = function(){
        var args = Array.apply(null, arguments); 
   
        return $.grep(this, function(value) {
           return $.inArray(value, args) &lt; 0;
        });
    }
  
    sitesNew = sites.remove("website2.com", "website3.com");
  
    console.log(sitesNew);
&lt;/script>
  
&lt;/body>
&lt;/html></pre>



<p class="wp-block-paragraph">Output</p>



<figure class="wp-block-image size-large is-resized is-style-default"><img fetchpriority="high" decoding="async" src="https://atcodex.com/wp-content/uploads/2020/09/Untitled.png" alt="output in console" class="wp-image-1056" width="590" height="330" srcset="https://atcodex.com/wp-content/uploads/2020/09/Untitled.png 590w, https://atcodex.com/wp-content/uploads/2020/09/Untitled-300x168.png 300w" sizes="(max-width: 590px) 100vw, 590px" /></figure>



<h2 class="wp-block-heading">Remove element using Using Lodash</h2>



<p class="wp-block-paragraph">To remove an element, we can use an external javascript library called Lodash. Lodash has the <code><a href="https://lodash.com/docs/#remove" target="_blank" rel="noreferrer noopener">remove</a>()</code> method which is very easy to use. All other methods in the Lodash are very easy to use and helpful which can done job for you in a second. You do not need to break the array  and manipulate for getting some work done in javascript. It have very helpful built in methods which you can use in any situation in the programming.</p>



<p class="wp-block-paragraph">In the below code  we are just passing the array in _.remove() and in which we have defined callback function when passed argument is == to 3.  </p>



<p class="wp-block-paragraph"><strong>NOTE : It make the changes in the existing array value</strong>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">var arr = [1, 2, 3, 3, 4, 5];
_.remove(arr, function(e) {
    return e === 3;
});
console.log(arr);

// Output:
// [ 1, 2, 4, 5 ]</pre>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">Remove element using Using Underscore</h2>



<p class="wp-block-paragraph">We can use Underscore library to solve the same problem. It has _.reject method which is same like _.remove() method in the Lodash. It works similarly like Lodash with some difference which is : it returns the new array after removing the passed value in the array. Old array value remains same. </p>



<p class="wp-block-paragraph">See the following code for an example:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">var arr = [1, 2, 3, 3, 4, 5];
var ret = _.reject(arr, function(e) {
    return e === 3;
});
console.log(arr);
console.log(ret);

// Output:
// [ 1, 2, 3, 3, 4, 5 ]
// [ 1, 2, 4, 5 ]
</pre>



<h2 class="wp-block-heading">Conclusion</h2>



<p class="wp-block-paragraph">We have explained 3 different method and by using them you can remove the one or more elements from the array in simple way. I hope you guys have liked the post, if you have any suggestion please comment below., i would love to help you.</p>
<p>The post <a href="https://atcodex.com/php/remove-multiple-elements-from-an-array-in-javascript-jquery/">Remove multiple elements from an array in Javascript/jQuery</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to access PHP variables in JavaScript or jQuery</title>
		<link>https://atcodex.com/how-to/how-to-access-php-variables-in-javascript-or-jquery/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Sat, 19 Sep 2020 13:47:27 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Array]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=1028</guid>

					<description><![CDATA[<p>Sometimes we need to access the PHP variables in javascript or jquery for the use in the application. In this article, let’s see how to pass data and variables from &#8230; </p>
<p>The post <a href="https://atcodex.com/how-to/how-to-access-php-variables-in-javascript-or-jquery/">How to access PHP variables in JavaScript or jQuery</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Sometimes we need to access the PHP variables in javascript or jquery for the use in the application. In this article, let’s see how to pass data and variables from PHP to JavaScript.</p>



<p class="wp-block-paragraph">If you have a simple string value in PHP and you want to access that value in javascript or jquery then  you have two options to do so. </p>



<p class="wp-block-paragraph">First, we can pass the data through cookies. In cookies, we can set the data in using PHP cookies and then access that cookies data in JavaScript and jquery.</p>



<p class="wp-block-paragraph">In the second method, we can simply access the PHP value direct in the JavaScript variable. You only need to initialize the variable in javascript and access the PHP value with all open and close PHP tag inside the Single Quotation mark (&#8221;).</p>



<p class="wp-block-paragraph">Let&#8217;s see how we can pass the PHP variable to JavaScript.</p>



<h2 class="wp-block-heading">Pass PHP variables in JavaScript or jQuery</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php
    $output = 'this is dummy text';
?>
&lt;script type="text/javascript">
    var output = '&lt;?php echo $output; ?>';
    document.write(output);
    console.log(output);

&lt;/script></pre>



<p class="wp-block-paragraph">You can simply check we just defined the value in PHP and then access that variable direct in the JavaScript.</p>



<h2 class="wp-block-heading">Pass a PHP array to a JavaScript function</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php
    $output = array('this', 'text','is good');
?>
&lt;script type="text/javascript">
    var output = &lt;?php echo json_encode($output); ?>;
    document.write(output);
    console.log(output);

&lt;/script></pre>



<p class="wp-block-paragraph">We can easily pass the PHP array to JavaScript, Only need to convert the PHP array to JSON using <strong>json_encode</strong> function and that can be accessed in the JavaScript.</p>



<h2 class="wp-block-heading">Pass Multidimensional Arrays from PHP to JavaScript</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php
// PHP array
$booksData = array(
    array(
        "title" => "title1",
        "author" => "author1"
    ),
    array(
        "title" => "title2",
        "author" => "author2"
    ),
    array(
        "title" => "title3",
        "author" => "author3"
    )
);
?>

&lt;script type="text/javascript">
var booksData = &lt;?php echo json_encode($booksData) ?>;
console.log(booksData); 
&lt;/script></pre>



<h2 class="wp-block-heading">Conclusion:</h2>



<p class="wp-block-paragraph">It is very easy to pass the data from PHP to JavaScript.  We have tried to make you understand with different case scenarios that must have helped you to understand all. </p>



<p class="wp-block-paragraph">If you have any queries related to this post, please comment below i would love to help you.  </p>



<p class="wp-block-paragraph">You can also check <a href="https://atcodex.com/php/how-to-get-a-random-value-from-a-php-array/" target="_blank" rel="noreferrer noopener">How to get a random key from a PHP array</a></p>
<p>The post <a href="https://atcodex.com/how-to/how-to-access-php-variables-in-javascript-or-jquery/">How to access PHP variables in JavaScript or jQuery</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Remove Empty Object From JSON in JavaScript</title>
		<link>https://atcodex.com/how-to/how-to-remove-empty-object-from-json-in-javascript/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Sat, 08 Aug 2020 07:37:19 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=682</guid>

					<description><![CDATA[<p>In this post, we have removed empty objects in JSON using Javascript. It is a very simple code snippet to remove all empty objects in JSON. Output</p>
<p>The post <a href="https://atcodex.com/how-to/how-to-remove-empty-object-from-json-in-javascript/">How to Remove Empty Object From JSON in JavaScript</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">In this post, we have removed empty objects in JSON using Javascript. It is a very simple code snippet to remove all empty objects in JSON. </p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;DOCTYPE html>
&lt;html>
&lt;head>
    &lt;title>How to remove empty object from json in javascript&lt;/title>
&lt;/head>
&lt;body>
   
&lt;script type="text/javascript">
   
    const objectData= { 
      b:'object',
      c: '',
      d: null,
      f: {v: 2, x: '', y: null, m: {a:'xyz'}}
    };
   
    const removeEmptyOrNullObject = (obj) => {
      Object.keys(obj).forEach(k =>
        (obj[k] &amp;&amp; typeof obj[k] === 'object') &amp;&amp; removeEmptyOrNullObject(obj[k]) ||
        (!obj[k] &amp;&amp; obj[k] !== undefined) &amp;&amp; delete obj[k]
      );
      return obj;
    };
   
    finalData = removeEmptyOrNullObject(objectData);
   
    console.log(finalData);
&lt;/script>
&lt;/body>
&lt;/html></pre>



<h2 class="wp-block-heading">Output</h2>



<figure class="wp-block-image size-large"><img decoding="async" width="337" height="322" src="https://atcodex.com/wp-content/uploads/2020/08/Untitled-2.png" alt="How to Remove Empty Object From JSON in JavaScript example" class="wp-image-684" srcset="https://atcodex.com/wp-content/uploads/2020/08/Untitled-2.png 337w, https://atcodex.com/wp-content/uploads/2020/08/Untitled-2-300x287.png 300w" sizes="(max-width: 337px) 100vw, 337px" /></figure>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://atcodex.com/how-to/how-to-remove-empty-object-from-json-in-javascript/">How to Remove Empty Object From JSON in JavaScript</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to upload a file with JavaScript and PHP</title>
		<link>https://atcodex.com/php/how-to-upload-a-file-with-javascript-and-php/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Thu, 23 Jul 2020 07:39:04 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=479</guid>

					<description><![CDATA[<p>File uploading option on a website is common. But to make it work from scratch seems a very difficult task and sometimes we have to waste lots of time to &#8230; </p>
<p>The post <a href="https://atcodex.com/php/how-to-upload-a-file-with-javascript-and-php/">How to upload a file with JavaScript and PHP</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">File uploading option on a website is common. But to make it work from scratch seems a very difficult task and sometimes we have to waste lots of time to figure out if things do not work properly. </p>



<p class="wp-block-paragraph">In this tutorial,  we will <strong>upload the file using javascript and PHP </strong>with a simple function. Javascript will be used to initiate the function and PHP to upload the file on the server.  Once the setup is done, you do not need to reload the file to upload one and more images simultaneously.</p>



<h2 class="wp-block-heading">HTML code to upload file</h2>



<p class="wp-block-paragraph">First, we need to create a file with the below code. The first input tag would be file to select the <strong>file</strong>. The second input tag would be <strong>button </strong>to initiate the javascript function.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;div >
  &lt;input type="file" name="file" id="file">
  &lt;input type="button" id="btn_uploadfile" 
     value="Upload" 
     onclick="uploadFile()" >
&lt;/div></pre>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">Javascript code to upload file</h2>



<p class="wp-block-paragraph">Create&nbsp;<code>uploadFile()</code>&nbsp;function which will be called on the <strong>Upload<em> </em></strong>button click in HTML.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">// Upload file
function uploadFile() {

   var files = document.getElementById("file").files;

   if(files.length > 0 ){

      var formData = new FormData();
      formData.append("file", files[0]);

      var xhttp = new XMLHttpRequest();

      // Set POST method and ajax file path
      xhttp.open("POST", "ajaxfile.php", true);

      // call on request changes state
      xhttp.onreadystatechange = function() {
         if (this.readyState == 4 &amp;&amp; this.status == 200) {

           var response = this.responseText;
           if(response == 1){
              alert("Upload successfully.");
           }else{
              alert("File not uploaded.");
           }
         }
      };

      // Send request with data
      xhttp.send(formData);

   }else{
      alert("Please select a file");
   }

}</pre>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">PHP code to upload file</h2>



<p class="wp-block-paragraph">Make a&nbsp;<code>ajaxfile.php</code>&nbsp;file and an&nbsp;<code>upload</code>&nbsp;folder to store the uploaded files.</p>



<p class="wp-block-paragraph">PHP will check the file extensions and only allow Pdf, Doc, Docx, Jpg, Png, Jpeg to be uploaded. If the user will try to upload other then this extension file the function will exit with response &#8216;0&#8217;;</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

if(isset($_FILES['file']['name'])){
   // file name
   $filename = $_FILES['file']['name'];

   // Location
   $location = 'upload/'.$filename;

   // file extension
   $file_extension = pathinfo($location, PATHINFO_EXTENSION);
   $file_extension = strtolower($file_extension);

   // Valid image extensions
   $valid_ext = array("pdf","doc","docx","jpg","png","jpeg");

   $response = 0;
   if(in_array($file_extension,$valid_ext)){
      // Upload file
      if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){
         $response = 1;
      } 
   }

   echo $response;
   exit;
}</pre>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link">Output</a></div>
</div>



<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="How to upload a file with JavaScript and PHP" width="735" height="413" src="https://www.youtube.com/embed/HXe-ockFdIE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link" href="https://atcodex.com/wp-content/uploads/2020/07/How-to-upload-a-file-with-JavaScript-and-PHP.zip">Download Source Code</a></div>
</div>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://atcodex.com/php/how-to-upload-a-file-with-javascript-and-php/">How to upload a file with JavaScript and PHP</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Remove HTML Tags from String using JavaScript</title>
		<link>https://atcodex.com/how-to/how-to-remove-html-tags-from-string-using-javascript/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Thu, 11 Jun 2020 12:48:50 +0000</pubDate>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=163</guid>

					<description><![CDATA[<p>Sometimes we get data from the server which contains HTML elements such as div span or internal CSS. We can either remove or parse those tags using backend language or &#8230; </p>
<p>The post <a href="https://atcodex.com/how-to/how-to-remove-html-tags-from-string-using-javascript/">How to Remove HTML Tags from String using JavaScript</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"> Sometimes we get data from the server which contains HTML elements such as div span or internal CSS. We can either remove or parse those tags using backend language or we can achieve the same with javascript replace() function. Using Regex in javascript we can remove any HLMT tag from the string. following is the code to remove the HMLT tags from string.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
var str = "&lt;div>Hello, &lt;h2>atcodex&lt;/h2>&lt;/div>";
var textData = str.replace(/&lt;\/?[^>]+(>|$)/g, "");
</pre>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://atcodex.com/how-to/how-to-remove-html-tags-from-string-using-javascript/">How to Remove HTML Tags from String using JavaScript</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to use Google map autocomplete location search API with example</title>
		<link>https://atcodex.com/javascript/how-to-use-google-map-autocomplete-location-search-api-with-example/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Tue, 19 May 2020 06:18:13 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=63</guid>

					<description><![CDATA[<p>What is an API API Stands for Application Programming Interface, which allows us to connect two or more applications to each other. Whenever you use an application like Whatsapp, Instagram, &#8230; </p>
<p>The post <a href="https://atcodex.com/javascript/how-to-use-google-map-autocomplete-location-search-api-with-example/">How to use Google map autocomplete location search API with example</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h4 class="wp-block-heading">What is an API</h4>



<p class="wp-block-paragraph">API Stands for Application Programming Interface,  which allows us to connect two or more applications to each other.  Whenever you use an application like Whatsapp, Instagram, or any other App on your phone, your phone is using an API to communicate with the server to show you data.</p>



<p class="wp-block-paragraph">When you use any app on your mobile,  the app sends the data to the server. Then the server process the data and send it back to the app. App then processes the data and display you in a readable way. This is what an API does. </p>



<p class="wp-block-paragraph">Following are the simple steps to enable the API </p>



<h3 class="wp-block-heading"><strong>1 – Login  to  </strong><a href="https://console.cloud.google.com/" target="_blank" rel="noreferrer noopener">https://console.cloud.google.com/</a></h3>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading"><strong>2 – Click on My project </strong></h3>



<p class="wp-block-paragraph">Click on my project (it might be different for you, for us its showing my project because we have already created a project with this name)</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="496" src="https://atcodex.com/wp-content/uploads/2020/05/3-1-1024x496.png" alt="" class="wp-image-65" srcset="https://atcodex.com/wp-content/uploads/2020/05/3-1-1024x496.png 1024w, https://atcodex.com/wp-content/uploads/2020/05/3-1-300x145.png 300w, https://atcodex.com/wp-content/uploads/2020/05/3-1-768x372.png 768w, https://atcodex.com/wp-content/uploads/2020/05/3-1.png 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading"><strong>3 – Click on New project </strong></h3>



<p class="wp-block-paragraph">Click on new project, fill the details and select</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="496" src="https://atcodex.com/wp-content/uploads/2020/05/4-1-1024x496.png" alt="" class="wp-image-67" srcset="https://atcodex.com/wp-content/uploads/2020/05/4-1-1024x496.png 1024w, https://atcodex.com/wp-content/uploads/2020/05/4-1-300x145.png 300w, https://atcodex.com/wp-content/uploads/2020/05/4-1-768x372.png 768w, https://atcodex.com/wp-content/uploads/2020/05/4-1.png 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading"><strong>4 – </strong>Enable API and Services </h3>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="496" src="https://atcodex.com/wp-content/uploads/2020/05/5-2-1024x496.png" alt="" class="wp-image-68" srcset="https://atcodex.com/wp-content/uploads/2020/05/5-2-1024x496.png 1024w, https://atcodex.com/wp-content/uploads/2020/05/5-2-300x145.png 300w, https://atcodex.com/wp-content/uploads/2020/05/5-2-768x372.png 768w, https://atcodex.com/wp-content/uploads/2020/05/5-2.png 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading"><strong>5 – </strong>Enable Maps Javascript API and Places API</h3>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="496" src="https://atcodex.com/wp-content/uploads/2020/05/1-1-1024x496.png" alt="" class="wp-image-69" srcset="https://atcodex.com/wp-content/uploads/2020/05/1-1-1024x496.png 1024w, https://atcodex.com/wp-content/uploads/2020/05/1-1-300x145.png 300w, https://atcodex.com/wp-content/uploads/2020/05/1-1-768x372.png 768w, https://atcodex.com/wp-content/uploads/2020/05/1-1.png 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="496" src="https://atcodex.com/wp-content/uploads/2020/05/2-1-1024x496.png" alt="" class="wp-image-70" srcset="https://atcodex.com/wp-content/uploads/2020/05/2-1-1024x496.png 1024w, https://atcodex.com/wp-content/uploads/2020/05/2-1-300x145.png 300w, https://atcodex.com/wp-content/uploads/2020/05/2-1-768x372.png 768w, https://atcodex.com/wp-content/uploads/2020/05/2-1.png 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading"><strong>6 – </strong>Create the Credentials </h3>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="496" src="https://atcodex.com/wp-content/uploads/2020/05/6-1-1024x496.png" alt="" class="wp-image-71" srcset="https://atcodex.com/wp-content/uploads/2020/05/6-1-1024x496.png 1024w, https://atcodex.com/wp-content/uploads/2020/05/6-1-300x145.png 300w, https://atcodex.com/wp-content/uploads/2020/05/6-1-768x372.png 768w, https://atcodex.com/wp-content/uploads/2020/05/6-1.png 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading"><strong>7 – </strong>Restrict the key </h3>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="496" src="https://atcodex.com/wp-content/uploads/2020/05/7-1-1024x496.png" alt="" class="wp-image-73" srcset="https://atcodex.com/wp-content/uploads/2020/05/7-1-1024x496.png 1024w, https://atcodex.com/wp-content/uploads/2020/05/7-1-300x145.png 300w, https://atcodex.com/wp-content/uploads/2020/05/7-1-768x372.png 768w, https://atcodex.com/wp-content/uploads/2020/05/7-1.png 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading"><strong>8 –  Key Restriction options</strong></h3>



<p class="wp-block-paragraph">There are multiple key restriction options for API to use on different platforms.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="301" height="592" src="https://atcodex.com/wp-content/uploads/2020/05/8.png" alt="" class="wp-image-74" srcset="https://atcodex.com/wp-content/uploads/2020/05/8.png 301w, https://atcodex.com/wp-content/uploads/2020/05/8-153x300.png 153w" sizes="(max-width: 301px) 100vw, 301px" /></figure>



<p class="wp-block-paragraph">Google API is not free, you have to pay the monthly bill on a usage basis. For billing, you need to attach your credit card to google account only then the API will work. And if still there is any problem, just inspect the element after clicking the right button in the browser, you will see each and every detail about the error in console.</p>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading"><strong>9 – Enable Billing</strong></h3>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="496" src="https://atcodex.com/wp-content/uploads/2020/05/9-1024x496.png" alt="" class="wp-image-75" srcset="https://atcodex.com/wp-content/uploads/2020/05/9-1024x496.png 1024w, https://atcodex.com/wp-content/uploads/2020/05/9-300x145.png 300w, https://atcodex.com/wp-content/uploads/2020/05/9-768x372.png 768w, https://atcodex.com/wp-content/uploads/2020/05/9.png 1366w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
&lt;!DOCTYPE html>
&lt;html>
  &lt;head>
    &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    &lt;meta charset="utf-8">
    &lt;title>Places Search Box&lt;/title>
    &lt;style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #description {
        font-family: Roboto;
        font-size: 15px;
        font-weight: 300;
      }

      #infowindow-content .title {
        font-weight: bold;
      }

      #infowindow-content {
        display: none;
      }

      #map #infowindow-content {
        display: inline;
      }

      .pac-card {
        margin: 10px 10px 0 0;
        border-radius: 2px 0 0 2px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        outline: none;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
        background-color: #fff;
        font-family: Roboto;
      }

      #pac-container {
        padding-bottom: 12px;
        margin-right: 12px;
      }

      .pac-controls {
        display: inline-block;
        padding: 5px 11px;
      }

      .pac-controls label {
        font-family: Roboto;
        font-size: 13px;
        font-weight: 300;
      }

      #pac-input {
        background-color: #fff;
        font-family: Roboto;
        font-size: 15px;
        font-weight: 300;
        margin-left: 12px;
        padding: 0 11px 0 13px;
        text-overflow: ellipsis;
        width: 400px;
      }

      #pac-input:focus {
        border-color: #4d90fe;
      }

      #title {
        color: #fff;
        background-color: #4d90fe;
        font-size: 25px;
        font-weight: 500;
        padding: 6px 12px;
      }
      #target {
        width: 345px;
      }
    &lt;/style>
  &lt;/head>
  &lt;body>
    &lt;input id="pac-input" class="controls" type="text" placeholder="Search Box">
    &lt;div id="map">&lt;/div>
    &lt;script>
      // This example adds a search box to a map, using the Google Place Autocomplete
      // feature. People can enter geographical searches. The search box will return a
      // pick list containing a mix of places and predicted search terms.

      // This example requires the Places library. Include the libraries=places
      // parameter when you first load the API. For example:
      // &lt;script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&amp;libraries=places">

      function initAutocomplete() {
        var map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: -33.8688, lng: 151.2195},
          zoom: 13,
          mapTypeId: 'roadmap'
        });

        // Create the search box and link it to the UI element.
        var input = document.getElementById('pac-input');
        var searchBox = new google.maps.places.SearchBox(input);
        map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

        // Bias the SearchBox results towards current map's viewport.
        map.addListener('bounds_changed', function() {
          searchBox.setBounds(map.getBounds());
        });

        var markers = [];
        // Listen for the event fired when the user selects a prediction and retrieve
        // more details for that place.
        searchBox.addListener('places_changed', function() {
          var places = searchBox.getPlaces();

          if (places.length == 0) {
            return;
          }

          // Clear out the old markers.
          markers.forEach(function(marker) {
            marker.setMap(null);
          });
          markers = [];

          // For each place, get the icon, name and location.
          var bounds = new google.maps.LatLngBounds();
          places.forEach(function(place) {
            if (!place.geometry) {
              console.log("Returned place contains no geometry");
              return;
            }
            var icon = {
              url: place.icon,
              size: new google.maps.Size(71, 71),
              origin: new google.maps.Point(0, 0),
              anchor: new google.maps.Point(17, 34),
              scaledSize: new google.maps.Size(25, 25)
            };

            // Create a marker for each place.
            markers.push(new google.maps.Marker({
              map: map,
              icon: icon,
              title: place.name,
              position: place.geometry.location
            }));

            if (place.geometry.viewport) {
              // Only geocodes have viewport.
              bounds.union(place.geometry.viewport);
            } else {
              bounds.extend(place.geometry.location);
            }
          });
          map.fitBounds(bounds);
        });
      }

    &lt;/script>
    &lt;script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&amp;libraries=places&amp;callback=initAutocomplete" async defer>&lt;/script>
  &lt;/body>
&lt;/html>

</pre>
<p>The post <a href="https://atcodex.com/javascript/how-to-use-google-map-autocomplete-location-search-api-with-example/">How to use Google map autocomplete location search API with example</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
