<?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>El Blog del Antonio &#187; Google Maps</title>
	<atom:link href="http://www.ramirezcobos.com/tag/google-maps/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ramirezcobos.com</link>
	<description>Programming Web with PHP, CSS, Javascript and ∞</description>
	<lastBuildDate>Wed, 28 Dec 2011 18:26:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Get Latitude and Longitude with Google Maps V3</title>
		<link>http://www.ramirezcobos.com/2010/01/22/get-latitude-and-longitude-with-google-maps-v3/</link>
		<comments>http://www.ramirezcobos.com/2010/01/22/get-latitude-and-longitude-with-google-maps-v3/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 14:56:24 +0000</pubDate>
		<dc:creator>Antonio Ramirez</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Google Maps]]></category>
		<guid isPermaLink="false">http://www.ramirezcobos.com/?p=251</guid>
		<description><![CDATA[I would like to share with you a little piece of code that I find quite useful in my applications. I do create lots of guides that require a small utility to find out the latitude and longitude of a business location from a control panel in order to display the maps appropiately on the Web. Here I  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ramirezcobos.com/wp-content/uploads/2010/01/Picture-22.png"><a href="http://www.ramirezcobos.com/wp-content/uploads/2010/03/Picture-22-300x198.png"><img class="alignright size-full wp-image-320" title="Picture-22-300x198" src="http://www.ramirezcobos.com/wp-content/uploads/2010/03/Picture-22-300x198.png" alt="" width="300" height="198" /></a></a>I would like to share with you a little piece of code that I find quite useful in my applications. I do create lots of guides that require a small utility to find out the latitude and longitude of a business location from a control panel in order to display the maps appropiately on the Web. Here I will do my best to explain a step procedure on how to do that -once you know the procedure, it is easy to create plugins or whatever you wish to do.</p>
<h3>Step 1</h3>
<p>First of all, lets make a reference to the new version of Google Maps. Check that we have to specify a parameter sensor=false. To find out more about this parameter please follow this <a href="http://code.google.com/intl/en-EN/apis/maps/documentation/#SpecifyingSensor">link</a>.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;
</pre>
<h3>Step 2</h3>
<p>Now we are going to write the HTML tags on the BODY of our document that will hold the map and the controls that will hold latitude, longitude and zoom level references. Also, see the CSS that control the size of the map holder.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;style&gt;
div#gmap {
width: 100%;
height: 300px;
}
&lt;/style&gt;
&lt;body&gt;
&lt;center&gt;
&lt;!-- MAP HOLDER --&gt;
&lt;div id="gmap"&gt;&lt;/div&gt;
&lt;!-- REFERENCES --&gt;
lat:&lt;span id="lat"&gt;&lt;/span&gt; lon:&lt;span id="lon"&gt;&lt;/span&gt;&lt;br/&gt;
zoom level: &lt;span id="zoom_level"&gt;&lt;/span&gt;
&lt;/center&gt;
&lt;/body&gt;
</pre>
<h3>Step 3</h3>
<p>Now, we are going to write the function that will display the map when the document loads. The function, that we will call &#8216;initialize&#8217; has different parts that we will describe now:</p>
<h4>Part 1</h4>
<p>Setting the map zoom level and its position in the world:</p>
<pre class="brush: jscript; title: ; notranslate">
var myLatlng = new google.maps.LatLng(38.971154274048345,1.415863037109375); // IBIZA <img src='http://www.ramirezcobos.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
var myOptions = {
zoom: 16,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("gmap"), myOptions);
</pre>
<h4>Part 2</h4>
<p>Placing a marker on the map specifying its center position (please refer to above code for LatLon location).</p>
<pre class="brush: jscript; title: ; notranslate">
// marker refers to a global variable
marker = new google.maps.Marker({
position: myLatlng,
map: map
});
</pre>
<h4>Part 3</h4>
<p>Now, the events that will take control of the marker center re-positioning and placing the information on the correspondent document objects (lat, lon, and zoom level).</p>
<pre class="brush: jscript; title: ; notranslate">
// if center changed then update lat and lon document objects
google.maps.event.addListener(map, 'center_changed', function() {
var location = map.getCenter();
document.getElementById("lat").innerHTML = location.lat();
document.getElementById("lon").innerHTML = location.lng();
// call function to reposition marker location
placeMarker(location);
});
// if zoom changed, then update document object with new info
google.maps.event.addListener(map, 'zoom_changed', function() {
zoomLevel = map.getZoom();
document.getElementById("zoom_level").innerHTML = zoomLevel;
});
// double click on the marker changes zoom level
google.maps.event.addListener(marker, 'dblclick', function() {
zoomLevel = map.getZoom()+1;
if (zoomLevel == 20) {
zoomLevel = 10;
}
document.getElementById("zoom_level").innerHTML = zoomLevel;
map.setZoom(zoomLevel);
});
</pre>
<h4>Part 4</h4>
<p>Initialize the document objects with default information</p>
<pre class="brush: jscript; title: ; notranslate">
document.getElementById("zoom_level").innerHTML = 16;
document.getElementById("lat").innerHTML = 38.971154274048345;
document.getElementById("lon").innerHTML = 1.415863037109375;
</pre>
<h4>Step 4</h4>
<p>Finally, we have to write the function that will reposition the marker on &#8216;zoom_changed&#8217; map event and call the &#8216;initialize&#8217; function on window load event.</p>
<pre class="brush: jscript; title: ; notranslate">
function placeMarker(location) {
var clickedLocation = new google.maps.LatLng(location);
marker.setPosition(location);
}
window.onload = function(){initialize()};
</pre>
<p>And that&#8217;s it, we have a great utility to plug onto our projects in order to find out the latitude and longitude of an address.</p>
<h3>DOWNLOAD</h3>
<p>I have included the working version of this tutorial for you to download. If you make any changes on the code in order to improve/add more functionality to it (that is easy fellows), please share it here with us.</p>
<div style="padding: 10px; text-align: center; background-color: #ffffff; border: 3px solid #dddddd;"><table style="border: 1px solid #CCC;" cellpadding="3" width="100%">
  <tr>
    <td width="35">
      <img src="http://www.ramirezcobos.com/wp-content/plugins/downloads-manager/img/icons/default.gif" alt="http://www.ramirezcobos.com/wp-content/plugins/downloads-manager/img/icons/default.gif">
    </td>
    <td>
      <b>download:</b> <a href="http://www.ramirezcobos.com/?file_id=9">Get Lat Lon Finder</a> <small>(1.41KB)</small><br />
      <b>added:</b> 22/01/2010 <br />
      <b>clicks:</b> 2663 <br />
    </td>
  </tr>
</table></div>
<script type="text/javascript"><!--
google_ad_client = "pub-7060132287364604";
/* 468x60, creado 16/03/10 */
google_ad_slot = "9029910384";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<a href="http://twitter.com/?status=RT%20%40%3A%20Get%20Latitude%20and%20Longitude%20with%20Google%20Maps%20V3%20-%20El%20Blog%20del%20Antonio%20http%3A%2F%2Fwww.ramirezcobos.com%2F2010%2F01%2F22%2Fget-latitude-and-longitude-with-google-maps-v3%2F" class="tweet-this" ><img src="http://www.ramirezcobos.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="Tweet this!" alt="Tweet this!" />Tweet this!</a>]]></content:encoded>
			<wfw:commentRss>http://www.ramirezcobos.com/2010/01/22/get-latitude-and-longitude-with-google-maps-v3/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: www.ramirezcobos.com @ 2012-02-06 17:43:41 by W3 Total Cache -->
