Advertisement

09.24.2008 at 11:06AM PDT, ID: 23759710
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.9

having trouble making "setZoom" and "setCenter" work in Google Maps

Asked by DWYee in JavaScript, Programming for ASP.NET

Tags: , ,

I'm just learning to use Google Maps...my inital attempt is in Javascript/HTML with ASP.NET 3.5 where there are 3 textboxes to supply 3 addresses (with address, city, state, country separated by commas).  I'm wanting to put up one marker for each address, then find their center point, pan to center it, then zoom in to include all 3 points relatively closely in a hybrid map (street map & satellite view).  I also want to have the 3 addresses displayed in links in a box to the right of the map, so that if you click on each link, an information window balloon box (with the address enclosed) pops up pointing to the corresponding marker on the map.
I've succeeded in accomplishing almost all of the above EXCEPT setting the correct zoom factor and centering the map.  Google provides a "GLatLngBounds" that you can store the bounds of the current map and extend it each time you set a marker with "bounds.extend(point)".  Then you are supposed to be able to use "map.setCenter(bounds.getCenter())" to set the center, and "map.panTo(bounds.getCenter()), to pan to the center, and finally "map.setZoom(map.getBoundsZoomLevel(bounds)) to set the zoom level.
I can only get the zoom and center to work IF I put an "alert("something")" right before the setCenter and setZoom lines.
I have found through research that Google's geocoder takes some time (100ms?) to execute while getting the address's latitude and longitude.  I've added "return = true" for each of my "setMarkers" function calls and only allow the setCenter & setZoom to execute if all 3 setMarkers calls returns are "True".  Still does not work.  What do I do to make this work?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
'***START .aspx.vb *********************************************
Partial Class property_tax_comps_tracker_GoogleMapTester
    Inherits BasePage
 
#Region " Declarations "
 
#End Region
 
#Region " Properties "
 
#End Region
 
#Region " Page Events "
 
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.Title = ""
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            SetAttributes()
        End If
    End Sub
 
#End Region
 
#Region " Control Events "
 
#End Region
 
#Region " Methods "
    Private Sub SetAttributes()
        btnSearch.Attributes.Add("onclick", "showAddress('" & txtAddress1.ClientID & "','" & txtAddress2.ClientID & "','" & txtAddress3.ClientID & "'); return false;")
        'btnSearch.Attributes.Add("onclick", "showAddress('100 Dundas St W, Toronto, ON, Canada'); return false;")
    End Sub
 
#End Region
 
End Class
'***** END .aspx.vb *******************************************
'***** START .aspx ********************************************
<%@ Page Language="VB" MasterPageFile="~/Base/popup.master" AutoEventWireup="false" CodeFile="GoogleMapTester.aspx.vb" Inherits="property_tax_comps_tracker_GoogleMapTester" title="Untitled Page" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="cphCafe" Runat="Server">
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA3KaHauTINRDt9Mo_uXaKKxTmazC1CCL-aZvJBl4evHylXtqSchRXl_AMYsY059CcaNzFMcDNGSqDoQ" type="text/javascript" language="javascript">
</script>
<script type="text/javascript">
        //<![CDATA[
      var side_bar_html = "";
      var gmarkers = [];
      var i = 0;
      //var map = new GMap2(document.getElementById("map"));
      var geocoder = new GClientGeocoder();
              
function showAddress(addr1,addr2,addr3) {
      //alert(addr)
      var address1 = document.getElementById(addr1).value
      var address2 = document.getElementById(addr2).value
      var address3 = document.getElementById(addr3).value
      //alert("Executing showAddress for " + address);
      var map = new GMap2(document.getElementById("map"));
      var bounds = new GLatLngBounds();
      var sw = new GLatLng();
      var ne = new GLatLng();
      var rtn1 = false;
      var rtn2 = false;
      var rtn3 = false;
      
      side_bar_html = '';
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      
      if (geocoder && GBrowserIsCompatible()) {
        try{
 
        //alert("Starting bounds = " + bounds);
 
        map.setCenter(new GLatLng(0,0),12)
        rtn1 = setMarkers(address1,0,map,bounds);
        rtn2 = setMarkers(address2,1,map,bounds);
        rtn3 = setMarkers(address3,2,map,bounds);
   
        //alert("bounds, just before centering = " + bounds)
        sw = bounds.getSouthWest();
        ne = bounds.getNorthEast();
        
        map.setMapType(G_HYBRID_MAP);
        
 //****NOTE: the setCenter & setZoom only work if the following alert is allowed to run! *******************
        alert("Zoom before setting = " + map.getBoundsZoomLevel(bounds));
        if (rtn1 == true && rtn2 == true && rtn3 == true){
            map.setCenter(bounds.getCenter());
            map.panTo(bounds.getCenter());
            map.setZoom(map.getBoundsZoomLevel(bounds));
        }
        
      }catch(Error){
      }
      }else{
        alert("Geocoder not here or Google Maps API is not compatible with this browser!");
      }
    }
 
    function setMarkers(address,j,map,bounds){
      try{
        geocoder.getLatLng(
              address,
              function(point) {
                if (!point) {
                  alert(address + " not found");
                } else {
                  var marker = new GMarker(point);
                  GEvent.addListener(marker, "click", function() {
                    marker.openInfoWindowHtml(address);});
                  map.addOverlay(marker);
                  gmarkers[j] = marker
                  var lat = point.y;
                  var lng = point.x;
                  var spot = new GLatLng(lat,lng)
                  bounds.extend(spot)
                  //alert("Bounds = " + bounds + " j = " + j)
                  side_bar_html += '<a href="javascript:myclick(' + j + ')">' + address + '</a><br>';
                  //alert("Adding marker for " + address + " , side_bar_html= " + side_bar_html + " , j = " + j );
                  document.getElementById("side_bar").innerHTML = side_bar_html;
                  marker.openInfoWindowHtml(address);
                }
              }
          );
          return true;
     }catch(e){
        alert(e.message);
        return false;
     }
     }
 
     function myclick(i){
        GEvent.trigger(gmarkers[i],"click");
    }
 
    //]]>    
</script>
<body  onunload="GUnload()">
    <table>
        <tr>
            <td>
                <div id="map" style="width: 800px; height: 600px"></div>
            </td>
            <td width="400" valign="top" style="text-decoration:underline; color:Blue;">
                <div id="side_bar"></div>
            </td>
        </tr>        
    </table>
    <table width="100%">
        <tr>
            <td align="right">
                Add new address markers here:
            </td>
            <td class="l_box_item">
                <asp:textbox id="txtAddress1" MaxLength="500" Width="600" runat="server"></asp:textbox>
                <asp:button ID="btnSearch" runat="server" Text="Search" />
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td class="l_box_item">
                <asp:TextBox ID="txtAddress2" MaxLength="500" Width="600" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>    
            <td class="l_box_item">
                <asp:TextBox ID="txtAddress3" MaxLength="500" Width="600" runat="server"></asp:TextBox>
            </td>
        </tr>
    </table>
</body>
</asp:Content>
[+][-]09.25.2008 at 04:33PM PDT, ID: 22575010

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09.25.2008 at 07:56PM PDT, ID: 22576235

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.25.2008 at 10:50PM PDT, ID: 22576880

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.26.2008 at 06:01AM PDT, ID: 22578974

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.26.2008 at 11:10PM PDT, ID: 22585682

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.29.2008 at 10:28AM PDT, ID: 22598554

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.03.2008 at 05:05AM PDT, ID: 22632963

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]10.03.2008 at 03:26PM PDT, ID: 22638529

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.07.2008 at 07:23AM PDT, ID: 22659659

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.08.2008 at 05:45AM PDT, ID: 22668371

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.08.2008 at 03:46PM PDT, ID: 22674241

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: JavaScript, Programming for ASP.NET
Tags: Javascript, IE7, Google Maps
Sign Up Now!
Solution Provided By: DanRollins
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.09.2008 at 11:14AM PDT, ID: 22680972

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628