forked from RoboxOrg/kodamaps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tomoka Baba
committed
Mar 30, 2015
0 parents
commit 539c8c5
Showing
6 changed files
with
483 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
(function() { | ||
var map, marker; | ||
function initialize() { | ||
var initLat = jQuery('#kodamaps-txt-input-lat').val() || 0; | ||
var initLng = jQuery('#kodamaps-txt-input-lng').val() || 0; | ||
var initZoom = (initLat || initLng) ? 16 : 0; | ||
var mapOptions = { | ||
zoom: initZoom, | ||
center: new google.maps.LatLng(initLat, initLng), | ||
}; | ||
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); | ||
|
||
var latLng = new google.maps.LatLng(initLat, initLng); | ||
marker = new google.maps.Marker({ | ||
position: latLng, | ||
map: map | ||
}); | ||
|
||
jQuery('#kodamaps-txt-input-address, #kodamaps-txt-input-lat, #kodamaps-txt-input-lng').change(function() { | ||
var geocoder = new google.maps.Geocoder(); | ||
if (this.id === 'kodamaps-txt-input-address') { | ||
var address = jQuery('#kodamaps-txt-input-address').val(); | ||
geocoder.geocode( | ||
{ | ||
'address': address | ||
}, | ||
function (results, status) { | ||
if (status === google.maps.GeocoderStatus.OK) { | ||
var latLng = new google.maps.LatLng(results[0].geometry.location.k, results[0].geometry.location.D); | ||
marker.position = latLng; | ||
marker.setMap(map); | ||
map.panTo(new google.maps.LatLng(marker.getPosition().k, marker.getPosition().D)); | ||
map.setZoom(16); | ||
jQuery('#kodamaps-txt-input-lat').val(marker.getPosition().k); | ||
jQuery('#kodamaps-txt-input-lng').val(marker.getPosition().D); | ||
jQuery('.kodamaps-postdata-address').val(address); | ||
jQuery('.kodamaps-postdata-lat').val(marker.getPosition().k); | ||
jQuery('.kodamaps-postdata-lng').val(marker.getPosition().D); | ||
} | ||
} | ||
); | ||
} else { | ||
var latLng = new google.maps.LatLng(jQuery('#kodamaps-txt-input-lat').val(), jQuery('#kodamaps-txt-input-lng').val()); | ||
geocoder.geocode( | ||
{ | ||
'latLng': latLng | ||
}, | ||
function (results, status) { | ||
if (status === google.maps.GeocoderStatus.OK) { | ||
var address = results[0].formatted_address; | ||
marker.position = latLng; | ||
marker.setMap(map); | ||
map.panTo(new google.maps.LatLng(marker.getPosition().k, marker.getPosition().D)); | ||
map.setZoom(16); | ||
jQuery('#kodamaps-txt-input-address').val(address); | ||
jQuery('#kodamaps-txt-input-lat').val(marker.getPosition().k); | ||
jQuery('#kodamaps-txt-input-lng').val(marker.getPosition().D); | ||
jQuery('.kodamaps-postdata-address').val(address); | ||
jQuery('.kodamaps-postdata-lat').val(marker.getPosition().k); | ||
jQuery('.kodamaps-postdata-lng').val(marker.getPosition().D); | ||
} | ||
} | ||
); | ||
} | ||
}); | ||
} | ||
window.onload = initialize; | ||
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
(function() { | ||
var map; | ||
function initialize() { | ||
var initLat = 0; | ||
var initLng = 0; | ||
initLat = (typeof kodamaps_posts !== 'undefined') && kodamaps_posts.centerLat !== '' ? parseFloat(kodamaps_posts.centerLat, 10) : initLat; | ||
initLng = (typeof kodamaps_posts !== 'undefined') && kodamaps_posts.centerLng !== '' ? parseFloat(kodamaps_posts.centerLng, 10) : initLng; | ||
var initZoom = (typeof kodamaps_posts !== 'undefined') && kodamaps_posts.zoom !== '' ? parseInt(kodamaps_posts.zoom,10) : 10; | ||
var address = (typeof kodamaps_posts !== 'undefined') && kodamaps_posts.centerAddr !== '' ? kodamaps_posts.centerAddr : ''; | ||
if (address !== '') { | ||
var geocoder = new google.maps.Geocoder(); | ||
geocoder.geocode( | ||
{ | ||
'address': address | ||
}, | ||
function (results, status) { | ||
if (status === google.maps.GeocoderStatus.OK) { | ||
initLat = results[0].geometry.location.k; | ||
initLng = results[0].geometry.location.D; | ||
var mapOptions = { | ||
zoom: initZoom, | ||
center: new google.maps.LatLng(initLat, initLng), | ||
mapTypeid: google.maps.MapTypeId.ROADMAP | ||
}; | ||
if(document.getElementById("map_canvas")) { | ||
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); | ||
} | ||
kodamaps_posts.postInfo.forEach(function(post) { | ||
var markerOption = { | ||
position: new google.maps.LatLng(post.lat, post.lng), | ||
map: map | ||
}; | ||
if (post.marker) { markerOption.icon = post.marker; } | ||
var marker = new google.maps.Marker(markerOption); | ||
}); | ||
} | ||
} | ||
); | ||
} else { | ||
var mapOptions = { | ||
zoom: initZoom, | ||
center: new google.maps.LatLng(initLat, initLng), | ||
mapTypeid: google.maps.MapTypeId.ROADMAP | ||
}; | ||
if(document.getElementById("map_canvas")) { | ||
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); | ||
} | ||
kodamaps_posts.postInfo.forEach(function(post) { | ||
var markerOption = { | ||
position: new google.maps.LatLng(post.lat, post.lng), | ||
map: map | ||
}; | ||
if (post.marker) { markerOption.icon = post.marker; } | ||
var marker = new google.maps.Marker(markerOption); | ||
}); | ||
} | ||
} | ||
window.onload = initialize; | ||
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(function() { | ||
var map; | ||
function initialize() { | ||
var initLat = (typeof kodamaps_post !== 'undefined') ? kodamaps_post.lat : 31.773827; | ||
var initLng = (typeof kodamaps_post !== 'undefined') ? kodamaps_post.lng : 130.7518837; | ||
var initZoom = (typeof kodamaps_post !== 'undefined') && kodamaps_post.zoom !== '' ? parseInt(kodamaps_post.zoom,10) : 10; | ||
var mapOptions = { | ||
zoom: initZoom, | ||
center: new google.maps.LatLng(initLat, initLng), | ||
mapTypeid: google.maps.MapTypeId.ROADMAP | ||
}; | ||
if(document.getElementById("map_canvas")) { | ||
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); | ||
var marker = new google.maps.Marker({ | ||
position: new google.maps.LatLng(kodamaps_post.lat, kodamaps_post.lng), | ||
map: map, | ||
icon: kodamaps_post.marker | ||
}); | ||
map.panTo(new google.maps.LatLng(initLat, initLng)); | ||
} | ||
} | ||
window.onload = initialize; | ||
}).call(this); |
Oops, something went wrong.