Autocomplete Address Search Module Using Google API and PHP

Autocomplete Address Search Module Using Google API and PHP

In this Post We Will Explain About is Autocomplete Address Search Module Using Google API and PHP With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to An autocomplete address search module Example

In this post we will show you Best way to implement Autocomplete for Addresses and Search Terms, hear for Autocomplete Address Search Module Using Google API and PHP with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Autocomplete Address Search Module Using Google API and PHP

Today We are going to Display We how you can create simple an autocomplete text box to address search module as well as all the place find on your need to website using simple steps by step Google Place API web service.

Also Read :  PHP GET Today Yesterday Last-7-Days This-Month-Last-Month This-Year Last-Year,All-Time

In our simple google autocomplete address or place search module we have simple used a autocomplete text box HTML using Jquery plugin named Like as a Select2 jquery plugin, for simple get key type and search all the palces some feature to our this demo google autocomplete module.

Steps to implement an autocomplete address search module

The first of all this first step is to simple grab a get a simple google’s API Key, We can find it here. Get API Key using Google

index.php

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>Place Autocomplete Example</title>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

        <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />

        <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
    </head>
    <body>
		<h1>Autocomplete Address Search Module Using Google API and PHP</h1>
        <select id="get_address" style="width:800px;"></select>

        <script type="text/javascript">
            $(document).ready(function(){

                $("#submit").click(function(){
                    var val_data = $("#get_address").val();
                    console.log(val_data);
                });

                $('select').select2({
                    placeholder: "Live write Search for your city",
                    ajax: {
                        url: function(dataparam){
                            return 'api.php?data='+dataparam.term; 
                        },
                        dataType: 'json', 
                        processResults: function (data) {
                            return {
                                results: $.map(data, function (liveitem) {
                                    return {
                                        text: liveitem.text,
                                        id: liveitem.text
                                    }
                                })
                            };
                        }
                    }

                });
            });
        </script>

    </body>
</html>

api.php

<?php

 $query_terms = $_GET['data'];

 $data_places = file_get_contents("https://maps.googleapis.com/maps/api/place/autocomplete/json?input=".$query_terms."&types=geocode&key={LIVE_YOUR_API_KEY}");

 $data_arr = array();
 $i=0;
 foreach(json_decode($data_places)->predictions as $item_place){
 $data_arr[$i] = array(
 'id' => $i,
 'text' => $item_place->description
 );
 $i++;
 }

 echo json_encode($data_arr);

?>

Also Read :  Apache Htaccess HTTP Server Tutorial

We just have to simple put above in this index.html and here api.php in the same your directory, and We replace here Live key like as a {YOUR_API_KEY} with your’s source code one.

Google Important Note

By using latest api google all location place API google very simple needs some google policy to following links (read this policy here),and then Google wants simple text their Like as a “powered by Google” logo to be your simple shown in the HTML drop-down.

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Also Read :  Simple PHP Create Custom Captcha Generator

Example

I hope you have Got What is Autocomplete search address form using Google map and get data into form example And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *