Introduction

In this blog, you can see the code for:
  1. Get the current location.
  2. Get location using longitude and latitude
For this map you have to add these js.
  1. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  2. <script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
Get current location
  1. if (navigator.geolocation) {
  2. navigator.geolocation.getCurrentPosition(success);
  3. }
  4. function success(position) {
  5. var address;
  6. var txtLongitude = position.coords.longitude;
  7. var txtLatitude = position.coords.latitude;
  8. var geocoder = new google.maps.Geocoder();
  9. var latlng = new google.maps.LatLng(txtLatitude, txtLongitude);
  10. geocoder.geocode({ 'latLng': latlng }, function (results, status) {
  11. if (status == google.maps.GeocoderStatus.OK) {
  12. if (results[1]) {
  13. alert(results[1].formatted_address + "\r\nLatitude: " + txtLatitude + "\r\nLongitude: " + txtLongitude);
  14. }
  15. }
  16. });
  17. }
Get location using longitude and latitude
  1. function CreateGoogleMap(latitude, longitude, address) {
  2. var loc, map, marker;
  3. loc = new google.maps.LatLng(latitude, longitude);
  4. map = new google.maps.Map(document.getElementById("Google_Map"), {
  5. zoom: 12,
  6. center: loc,
  7. mapTypeId: google.maps.MapTypeId.ROADMAP
  8. });
  9. marker = new google.maps.Marker({
  10. map: map,
  11. icon: pointer.png",
  12. position: loc,
  13. visible: true
  14. });
  15. google.maps.event.trigger(map, "resize");
  16. }
For complete code, you can download the attachment.
Thanks