Auto Complete City Google Map API In Laravel

Auto Complete City Google Map API In Laravel

In this post we will give you information about Auto Complete City Google Map API In Laravel. Hear we will give you detail about Auto Complete City Google Map API In LaravelAnd how to use it also give you demo for it if it is necessary.

Hello, everyone in this tutorials we are share with you how to use google map’s autocompleted fill city API in youe laravel application in your form. this is very easy and many time require in any application in register form and any other form.


In this tutorials we are show you country base autocomplete city in text box.


We are create one simple example for autocomplete city API usign google map’s API. simple follow this step for integrate in your laravel application


Step : 1 Create Route


First we are create one route in your routes/web.php file




Route::get('auto-complete-city', 'AutoCompleteController@index')->name('auto-complete-city');



Step : 2 Create controller


Now we are create AutoCompleteController in app/Http/Controllers folder




namespace AppHttpControllers;

use AppHttpRequests;
use IlluminateHttpRequest;
use DB;
use PDF;

class AutoCompleteController extends Controller
{
    /**
     * Show the application dashboard.
     *
     * @return IlluminateHttpResponse
     */
    public function index(Request $request)
    {        
        return view('auto-complete-city');
    }
}



Step : 3 Create Blade File



Into the last we are create one blade file and simple put into it following .




<!DOCTYPE html>
<html>
<head>
	<title>User list - PDF</title>
	<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
	<script src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_MAP_API_KEY&libraries=places®ion=in"></script>
</head>
<body>
<div >
	<form>
		<div >
            <label>City<star>*</star></label>
            <input type="text" name="city" placeholder="City"  value="{{ old('city') }}" id="city">
        </div>
	</form>
	<script type="text/javascript">
		function initialize() {
		    var options = {
		        types: ['(cities)'],
		        componentRestrictions: {country: "in"}
		    };
		    var input = document.getElementById('city');
		    var autocomplete = new google.maps.places.Autocomplete(input, options);
		}
		google.maps.event.addDomListener(window, 'load', initialize);
	</script>
</div>
</body>
</html>



Now we are ready to run our example so run bellow command ro quick run:




php artisan serve



Now you can open bellow URL on your browser:




http://localhost:8000/auto-complete-city



If you face any problem then please write a comment or give some suggestions for improvement. Thanks…

Hope this and post will helped you for implement Auto Complete City Google Map API In Laravel. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

79  +    =  88

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US