Use Google's geocode on Bing Maps. #221
This commit is contained in:
parent
86963a2913
commit
3720367ae7
1 changed files with 41 additions and 54 deletions
|
|
@ -1,4 +1,7 @@
|
|||
<script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap&key={{ bingmaps_api_key|raw }}' async defer></script>
|
||||
<script src="//maps.google.com/maps/api/js?key={{ gmaps_api_key|raw }}" type="text/javascript"></script>
|
||||
<script src="/assets/vendors/custom/gmaps/gmaps.js" type="text/javascript"></script>
|
||||
|
||||
<script>
|
||||
|
||||
var form_in_process = false;
|
||||
|
|
@ -40,68 +43,52 @@ function GetMap()
|
|||
$('#map_lng').val(locTemp.longitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function geocodeQuery(query) {
|
||||
var searchRequest = {
|
||||
where: query,
|
||||
callback: function (r) {
|
||||
// clear map
|
||||
map.entities.clear();
|
||||
// Add the first result
|
||||
if (r && r.results && r.results.length > 0) {
|
||||
pin = new Microsoft.Maps.Pushpin(r.results[0].location, {
|
||||
draggable: false,
|
||||
icon: '/assets/images/icon-destination.png'
|
||||
});
|
||||
map.entities.push(pin);
|
||||
map.setView({
|
||||
center: location
|
||||
});
|
||||
// set value in hidden input
|
||||
$('#map_lat').val(locTemp.latitude);
|
||||
$('#map_lng').val(locTemp.longitude);
|
||||
}
|
||||
else {
|
||||
alert('wala');
|
||||
var handleAction = function() {
|
||||
var text = $.trim($('#m_gmap_address').val());
|
||||
GMaps.geocode({
|
||||
address: text,
|
||||
callback: function(results, status) {
|
||||
map.entities.clear();
|
||||
if (status == 'OK') {
|
||||
var location = results[0].geometry.location;
|
||||
var lat = location.lat();
|
||||
var lng = location.lng();
|
||||
|
||||
// show in map
|
||||
var loc = new Microsoft.Maps.Location(lat, lng);
|
||||
pin = new Microsoft.Maps.Pushpin(loc, {
|
||||
draggable: false,
|
||||
icon: '/assets/images/icon-destination.png'
|
||||
});
|
||||
|
||||
map.entities.push(pin);
|
||||
map.setView({
|
||||
center: loc
|
||||
});
|
||||
|
||||
// set value in hidden input
|
||||
$('#map_lat').val(locTemp.latitude);
|
||||
$('#map_lng').val(locTemp.longitude);
|
||||
}
|
||||
},
|
||||
errorCallback: function (e) {
|
||||
alert("No results found");
|
||||
}
|
||||
};
|
||||
alert(query);
|
||||
searchManager.geocode(searchRequest);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('#m_gmap_btn').click(function(e) {
|
||||
e.preventDefault();
|
||||
handleAction();
|
||||
});
|
||||
|
||||
var handleAction = function() {
|
||||
var text = $.trim($('#m_gmap_address').val());
|
||||
if (!searchManager) {
|
||||
// create an instance of the search manager
|
||||
Microsoft.Maps.loadModule('Microsoft.Maps.Search', function() {
|
||||
searchManager = new Microsoft.Maps.Search.SearchManager(map);
|
||||
geocodeQuery(encodeURIComponent(text));
|
||||
});
|
||||
} else {
|
||||
map.entities.clear();
|
||||
geocodeQuery(encodeURIComponent(text));
|
||||
}
|
||||
}
|
||||
|
||||
$('#m_gmap_btn').click(function(e) {
|
||||
$("#m_gmap_address").keypress(function(e) {
|
||||
var keycode = (e.keyCode ? e.keyCode : e.which);
|
||||
if (keycode == '13') {
|
||||
e.preventDefault();
|
||||
handleAction();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$("#m_gmap_address").keypress(function(e) {
|
||||
var keycode = (e.keyCode ? e.keyCode : e.which);
|
||||
if (keycode == '13') {
|
||||
e.preventDefault();
|
||||
handleAction();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
$(function() {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue