Advertisement
saurabh6790

mapwitherp

Sep 25th, 2013
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var geocoder;
  2. var map;
  3. var markers = [];
  4. //wn.provide('http://maps.google.com/maps/api/js?sensor=false');
  5. gmap = Class.extend({
  6.     // alert('2')
  7.     init: function() {
  8.         alert('1');
  9.         alert('2');
  10.         geocoder = new google.maps.Geocoder();
  11.         var latlng = new google.maps.LatLng(42.095287, -79.3185139);
  12.         var myOptions = {
  13.             zoom: 10,
  14.             center: latlng,
  15.             mapTypeId: google.maps.MapTypeId.ROADMAP
  16.         };
  17.         map = new google.maps.Map(document.getElementById("map_canvas"),
  18.         myOptions);
  19.     },
  20.     setAllMap: function(map) {
  21.         alert(this.parent)
  22.         for (var i = 0; i < markers.length; i++) {
  23.             markers[i].setMap(map);
  24.         }
  25.     },
  26.     clearOverlays: function () {
  27.         this.setAllMap(null);
  28.     },
  29.     // Shows any overlays currently in the array.
  30.     showOverlays: function () {
  31.         this.setAllMap(map);
  32.     },
  33.     // Deletes all markers in the array by removing references to them.
  34.     deleteOverlays: function () {
  35.         this.clearOverlays();
  36.         markers = [];
  37.     },
  38.     codeAddress: function () {
  39.         alert(this.parent)
  40.     //The first line of the function should use getElementById to get the address from the text box and place it
  41.     //into a variable we'll call sAddress.
  42.         var sAddress = document.getElementById("inputTextAddress").value;
  43.         //Call the geocode method of the geocoder object, this will take two passed in parameters.  The first is
  44.         //the GeocoderRequest, this says what kind of request is being made and what the request value is.  
  45.         //The second is the callback function that will be used to process the results.
  46.         geocoder.geocode( { 'address': sAddress}, function(results, status) {
  47.             //The callback function should first check the status value of the callback function.  Use an IF statement
  48.             //to test the result, check to see if the status equal google.maps.GeocoderStatus.OK.  Also add an
  49.             //ELSE clause to the if statement as well.
  50.             if (status == google.maps.GeocoderStatus.OK) {
  51.                 //If the status equals OK, call the setCenter method of the map object variable.  You will pass this
  52.                 //method the results first geometry location.
  53.                 map.setCenter(results[0].geometry.location);
  54.                 //Next use the same result geometry location to add a map marker to the map object variable.  Create a new
  55.                 //variable, we'll call it oMarker, it will be created as a new google.maps.Marker.  The new method take two
  56.                 //parmaters, the first is the map object that you're adding the marker to, and the second is the
  57.                 //position to place the marker which is again the first results geometry location.
  58.                 deleteOverlays();
  59.                 alert("mgagg"+results[0]);
  60.                 var marker = new google.maps.Marker({
  61.                     map: map,
  62.                  
  63.                     position: results[0].geometry.location
  64.                 });
  65.                 markers.push(marker);
  66.             }
  67.             else {
  68.                 //Finally we're going to add an alert message to the ELSE to let the user know that the Geocode didn't
  69.                 //work like it should have.  You can use the status to give a bit more information rather than just saying
  70.                 //that it didn't work.
  71.                 alert("Geocode was not successful for the following reason: " + status);
  72.             }
  73.         });
  74.     }
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement