<?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>geoLocation &#8211; Best DevOps</title>
	<atom:link href="https://www.bestdevops.com/tag/geolocation/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.bestdevops.com</link>
	<description>Lets Learn, Do it &#38; Share! Thats a Best DevOps!!!</description>
	<lastBuildDate>Thu, 05 Aug 2021 07:00:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>
	<item>
		<title>How to get current city name using google maps API (Laravel)</title>
		<link>https://www.bestdevops.com/how-to-get-current-city-name-using-google-maps-api-laravel/</link>
		
		<dc:creator><![CDATA[pradeep]]></dc:creator>
		<pubDate>Thu, 05 Aug 2021 06:53:25 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[currentAddress]]></category>
		<category><![CDATA[CurrentCity]]></category>
		<category><![CDATA[CurrentCountry]]></category>
		<category><![CDATA[geoLocation]]></category>
		<category><![CDATA[googleMAPsApi]]></category>
		<category><![CDATA[Location]]></category>
		<guid isPermaLink="false">https://www.bestdevops.com/?p=18691</guid>

					<description><![CDATA[First of all we need to get a google maps API, go through this documentation to get an API of [&#8230;]]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="725" height="174" src="https://www.bestdevops.com/wp-content/uploads/2021/08/location-1.png" alt="" class="wp-image-18695" srcset="https://www.bestdevops.com/wp-content/uploads/2021/08/location-1.png 725w, https://www.bestdevops.com/wp-content/uploads/2021/08/location-1-300x72.png 300w" sizes="(max-width: 725px) 100vw, 725px" /><figcaption>Create this html form and make sure you have two hidden input with id let and long</figcaption></figure>



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



<h3 class="wp-block-heading">First of all we need to get  a google maps API, go through this <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">documentation </a>to get an API of your own.<br>https://developers.google.com/maps/documentation/javascript/get-api-key</h3>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="251" src="https://www.bestdevops.com/wp-content/uploads/2021/08/image-33-1024x251.png" alt="" class="wp-image-18692" srcset="https://www.bestdevops.com/wp-content/uploads/2021/08/image-33-1024x251.png 1024w, https://www.bestdevops.com/wp-content/uploads/2021/08/image-33-300x73.png 300w, https://www.bestdevops.com/wp-content/uploads/2021/08/image-33-768x188.png 768w, https://www.bestdevops.com/wp-content/uploads/2021/08/image-33.png 1307w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>You only need Geocoding API and Maps JavaScript API</figcaption></figure>



<h3 class="wp-block-heading">Place this script in your blade file if your are using Laravel or in your HTML inside body tags.</h3>


<pre class="wp-block-code"><span><code class="hljs language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&amp;callback=initMap&amp;libraries=&amp;v=weekly"</span><span class="hljs-attr">defer</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></span></pre>


<p class="wp-block-paragraph">Make sure to put your API key in the place of YOUR_API_KEY in provided script above </p>



<h4 class="wp-block-heading">Next thing you need to do after initializing the map is to create a method in jQuery for the call-back method  <em>initMap</em> , it should match the the same callback in the script </h4>



<h3 class="wp-block-heading">After this first thing we need to do is to get our current location (let, long)</h3>


<pre class="wp-block-code"><span><code class="hljs language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn btn-success"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">"getAddress()"</span>&gt;</span>Get Location<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></code></span></pre>


<script src="https://gist.github.com/pradeeprjth/b4cc691c69dc4d97633bf7d311254cfe.js"></script>



<h2 class="wp-block-heading">What we have done in above js code</h2>



<ul class="wp-block-list"><li>getAddress method will get the current let long using geolocation that is provided by HTML;</li><li>in the second function we are setting the value of two hidden input fields with the current let long;</li><li>The initMap method will be called by our script that we initialized earlier</li><li>The initMap method will call geocodeLatLng  method to get the current let long from those hidden input</li><li>Next thing we&#8217;re doing is splitting and formatting the let long value to provide it to geocoder</li><li>you will get your current city name in this address variable</li><li>Console Log the result variable and you&#8217;ll find more properties provide by geocode like long name, short name, postal code, area building number etc etc</li></ul>



<h2 class="wp-block-heading">That&#8217;s it hope this help </h2>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
