forked from vicchi/maps-api-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmxn-geocoder.js
69 lines (54 loc) · 1.63 KB
/
mxn-geocoder.js
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
var mapstraction;
var geocoder;
var address;
function initialize() {
mapstraction = new mxn.Mapstraction('map','ovi');
mapstraction.setCenterAndZoom(new mxn.LatLonPoint(0,0), 1);
geocoder = new mxn.Geocoder('ovi', geocode_return, error_callback);
address = "Schönhauser Allee 180, Berlin, Germany";
geocoder.geocode(address);
}
function error_callback(status) {
geocode_status = document.getElementById("geocode_status");
geocode_status.innerHTML = status;
}
function geocode_return(location) {
var infoBubble;
var components = [];
geocode_status = document.getElementById("geocode_status");
geocode_status.innerHTML = "geocoding succeeded";
// display the map centered on a latitude and longitude (Google zoom levels)
mapstraction.setCenterAndZoom(location.point, 15);
mapstraction.addControls({
pan: true,
zoom: 'small',
map_type: true
});
// create a marker positioned at a lat/lon
geocode_marker = new mxn.Marker(location.point);
if (location.street) {
components.push(location.street);
}
if (location.locality) {
components.push(location.locality);
}
if (location.postcode) {
components.push(location.postcode);
}
if (location.region) {
components.push(location.region);
}
if (location.country) {
components.push(location.country);
}
var bubble = components.join(', ');
geocode_marker.setInfoBubble(bubble);
// display marker
mapstraction.addMarker(geocode_marker);
// open the marker
geocode_marker.openBubble();
}
function do_geocode() {
address = document.getElementById("address").value;
geocoder.geocode(address);
}