Advertisement

08.18.2008 at 09:40AM PDT, ID: 23656948
[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!

9.2

Google Maps API display locations from combo box

Asked by dlan75 in JavaScript

Tags:

Hi,
I am starting to play with the google maps api and what I would like to do is the following :
I found on the google maps examples the code attached below which can be found here : http://code.google.com/apis/maps/documentation/examples/geocoding-cache.html and which displays a city.

So to make it simple, instead of having the engine searching for the address I would like it to display what is in the combobox according to each element's coordinates (that I would have entered before).

How could I do that? (hope that was clear enough)

Thx in advanceStart 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:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Google Maps JavaScript API Example: Geocoding Cache</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA" 
      type="text/javascript"></script>
    <script type="text/javascript">
 
  // Builds an array of geocode responses for the 5 cities.
  var city = [
    {
      name: "Washington, DC",
      Status: {
        code: 200,
        request: "geocode"
      },
      Placemark: [
        {
          address: "Washington, DC, USA",
          population: "0.563M",
          Point: {
            coordinates: [-77.036667, 38.895000, 0]
          },
          AddressDetails: {
            Country: {
              CountryNameCode: "US",
              AdministrativeArea: {
              AdministrativeAreaName: "DC",
                Locality: {LocalityName: "Washington"}
              }
            }
          }
        }
      ]
    },
    {
      name: "Tokyo, Japan",
      Status: {
        code: 200,
        request: "geocode"
      },
      Placemark: [
        {
          address: "Tokyo, Japan",
          population: "12.527M",
          Point: {
            coordinates: [139.770004, 35.669998, 0]
          },
            AddressDetails: {
            Country: {
              CountryNameCode: "US",
              AdministrativeArea: {
                AdministrativeAreaName: "CA",
                Locality: {LocalityName: "Los Angeles"}
              }
            }
          }
        }
      ]
    },
    {
      name: "Paris, France",
      Status: {
        code: 200,
        request: "geocode"
      },
      Placemark: [
        {
          address: "Paris, France",
          population: "2.144M",
          Point: {
            coordinates: [2.351019, 48.856662, 0]
          },
          AddressDetails: {
            Country: {
              CountryNameCode: "FR",
              Locality: {LocalityName: "Paris"}
            }
          }
        }
      ]
    },
    {
      name: "Rome, Italy",
      Status: {
        code: 200,
        request: "geocode"
      },
      Placemark: [
        {
          address: "Rome, Italy",
          population: "2.553M",
          Point: {
            coordinates: [12.482181, 41.895431, 0]
          },
          AddressDetails: {
            Country: {
              CountryNameCode: "IT",
              Locality: {LocalityName: "Roma"}
            }
          }
        }
      ]
    },
    {
      name: "Berlin, Germany",
      Status: {
        code: 200,
        request: "geocode"
      },
      Placemark: [
        {
          address: "Berlin, Germany",
          population: "3.396M",
          Point: {
            coordinates: [13.411895, 52.523781, 0]
          },
          AddressDetails: {
            Country: {
              CountryNameCode: "DE",
              Locality: {LocalityName: "Berlin"}
            }
          }
        }
      ]
    },
    {
      name: "Madrid, Spain",
      Status: {
        code: 200,
        request: "geocode"
      },
      Placemark: [
        {
          address: "Madrid, Spain",
          population: "3.228M",
          Point: {
            coordinates: [-3.703270, 40.416712, 0]
          },
          AddressDetails: {
            Country: {
              CountryNameCode: "ES",
              Locality: {LocalityName: "Madrid"}
            }
          }
        }
      ]
    }
  ];
 
 
  var map;
  var geocoder;
 
  // CapitalCitiesCache is a custom cache that extends the standard GeocodeCache.
  // We call apply(this) to invoke the parent's class constructor.
  function CapitalCitiesCache() {
    GGeocodeCache.apply(this);
  }
 
  // Assigns an instance of the parent class as a prototype of the
  // child class, to make sure that all methods defined on the parent
  // class can be directly invoked on the child class.
  CapitalCitiesCache.prototype = new GGeocodeCache();
 
  // Override the reset method to populate the empty cache with
  // information from our array of geocode responses for capitals.
  CapitalCitiesCache.prototype.reset = function() {
    GGeocodeCache.prototype.reset.call(this);
    for (var i in city) {
      this.put(city[i].name, city[i]);
    }
  }
 
  function initialize() {
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(37.441944, -122.141944), 6);
    geocoder = new GClientGeocoder();
    geocoder.setCache(new CapitalCitiesCache());
  }
 
  function addAddressToMap(response) {
    map.clearOverlays();
 
    if (response && response.Status.code != 200) {
      alert("Unable to locate " + decodeURIComponent(response.name));
    } else {
      var place = response.Placemark[0];
      var point = new GLatLng(place.Point.coordinates[1],
                              place.Point.coordinates[0]);
      map.setCenter(point, 6);
      map.openInfoWindowHtml(point, "<b>City:</b> " + place.address
       + "<br><b>Population:</b> " + place.population);
    }
  }
 
  function findCity(which) {
    if (which != 0) {
      geocoder.getLocations(city[which - 1].name, addAddressToMap);
    }
  }
  </script>
</head>
<body onload="initialize()">
  <table>
  <tr>
    <td align="center">
      <b>Go to:</b>
      <select onchange="findCity(this.selectedIndex)">
        <option>Select capital</option>
        <option>Washington, USA</option>
        <option>Tokyo, Japan</option>
        <option>Paris, France</option>
        <option>Rome, Italy</option>
        <option>Berlin, Germany</option>
        <option>Madrid, Spain</option>
      </select>
    </td>
  </tr>
  <tr>
    <td>
      <div id="map_canvas" class="map" style="width:450px;height:400px"></div>
    </td>
  </tr>
  </table>
</body>
</html>
 
 
[+][-]08.20.2008 at 02:46AM PDT, ID: 22267611

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

Zone: JavaScript
Tags: Java Script
Sign Up Now!
Solution Provided By: EZFrag
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.20.2008 at 04:54AM PDT, ID: 22268390

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.

 
[+][-]08.20.2008 at 05:21AM PDT, ID: 22268593

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

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

 
[+][-]08.20.2008 at 07:31AM PDT, ID: 22269929

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