Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var geocoder;
- var map;
- var markers = [];
- //wn.provide('http://maps.google.com/maps/api/js?sensor=false');
- gmap = Class.extend({
- // alert('2')
- init: function() {
- alert('1');
- alert('2');
- geocoder = new google.maps.Geocoder();
- var latlng = new google.maps.LatLng(42.095287, -79.3185139);
- var myOptions = {
- zoom: 10,
- center: latlng,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- map = new google.maps.Map(document.getElementById("map_canvas"),
- myOptions);
- },
- setAllMap: function(map) {
- alert(this.parent)
- for (var i = 0; i < markers.length; i++) {
- markers[i].setMap(map);
- }
- },
- clearOverlays: function () {
- this.setAllMap(null);
- },
- // Shows any overlays currently in the array.
- showOverlays: function () {
- this.setAllMap(map);
- },
- // Deletes all markers in the array by removing references to them.
- deleteOverlays: function () {
- this.clearOverlays();
- markers = [];
- },
- codeAddress: function () {
- alert(this.parent)
- //The first line of the function should use getElementById to get the address from the text box and place it
- //into a variable we'll call sAddress.
- var sAddress = document.getElementById("inputTextAddress").value;
- //Call the geocode method of the geocoder object, this will take two passed in parameters. The first is
- //the GeocoderRequest, this says what kind of request is being made and what the request value is.
- //The second is the callback function that will be used to process the results.
- geocoder.geocode( { 'address': sAddress}, function(results, status) {
- //The callback function should first check the status value of the callback function. Use an IF statement
- //to test the result, check to see if the status equal google.maps.GeocoderStatus.OK. Also add an
- //ELSE clause to the if statement as well.
- if (status == google.maps.GeocoderStatus.OK) {
- //If the status equals OK, call the setCenter method of the map object variable. You will pass this
- //method the results first geometry location.
- map.setCenter(results[0].geometry.location);
- //Next use the same result geometry location to add a map marker to the map object variable. Create a new
- //variable, we'll call it oMarker, it will be created as a new google.maps.Marker. The new method take two
- //parmaters, the first is the map object that you're adding the marker to, and the second is the
- //position to place the marker which is again the first results geometry location.
- deleteOverlays();
- alert("mgagg"+results[0]);
- var marker = new google.maps.Marker({
- map: map,
- position: results[0].geometry.location
- });
- markers.push(marker);
- }
- else {
- //Finally we're going to add an alert message to the ELSE to let the user know that the Geocode didn't
- //work like it should have. You can use the status to give a bit more information rather than just saying
- //that it didn't work.
- alert("Geocode was not successful for the following reason: " + status);
- }
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement