1
1
function initialize ( ) {
2
2
3
3
var mapOptions , map , marker , searchBox ,
4
- infoWindow = '' ;
4
+ infoWindow = '' ,
5
5
addressEl = document . querySelector ( '#map-search' ) ,
6
6
latEl = document . querySelector ( '.latitude' ) ,
7
7
longEl = document . querySelector ( '.longitude' ) ,
8
- element = document . getElementById ( 'map-canvas' ) ;
8
+ element = document . getElementById ( 'map-canvas' ) ,
9
+ city = document . querySelector ( '.reg-input-city' ) ;
9
10
10
11
mapOptions = {
11
12
// How far the maps zooms in.
12
13
zoom : 8 ,
13
14
// Current Lat and Long position of the pin/
14
- center : new google . maps . LatLng ( - 34.397 , 150.644 ) ,
15
+ center : new google . maps . LatLng ( 18.5204 , 73.8567 ) ,
15
16
// center : {
16
17
// lat: -34.397,
17
18
// lng: 150.644
@@ -86,11 +87,11 @@ function initialize() {
86
87
} ) ;
87
88
88
89
89
- /**
90
+ /**
90
91
* Finds the new position of the marker when the marker is dragged.
91
92
*/
92
93
google . maps . event . addListener ( marker , "dragend" , function ( event ) {
93
- var lat , long , address ;
94
+ var lat , long , address , resultArray , citi ;
94
95
95
96
console . log ( 'i am dragged' ) ;
96
97
lat = marker . getPosition ( ) . lat ( ) ;
@@ -100,6 +101,16 @@ function initialize() {
100
101
geocoder . geocode ( { latLng : marker . getPosition ( ) } , function ( result , status ) {
101
102
if ( 'OK' === status ) { // This line can also be written like if ( status == google.maps.GeocoderStatus.OK ) {
102
103
address = result [ 0 ] . formatted_address ;
104
+ resultArray = result [ 0 ] . address_components ;
105
+
106
+ // Get the city and set the city input value to the one selected
107
+ for ( var i = 0 ; i < resultArray . length ; i ++ ) {
108
+ if ( resultArray [ i ] . types [ 0 ] && 'administrative_area_level_2' === resultArray [ i ] . types [ 0 ] ) {
109
+ citi = resultArray [ i ] . long_name ;
110
+ console . log ( citi ) ;
111
+ city . value = citi ;
112
+ }
113
+ }
103
114
addressEl . value = address ;
104
115
latEl . value = lat ;
105
116
longEl . value = long ;
@@ -125,4 +136,4 @@ function initialize() {
125
136
} ) ;
126
137
127
138
128
- }
139
+ }
0 commit comments