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 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>
|
<script>
|
||||||
|
|
||||||
var form_in_process = false;
|
var form_in_process = false;
|
||||||
|
|
@ -40,68 +43,52 @@ function GetMap()
|
||||||
$('#map_lng').val(locTemp.longitude);
|
$('#map_lng').val(locTemp.longitude);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function geocodeQuery(query) {
|
var handleAction = function() {
|
||||||
var searchRequest = {
|
var text = $.trim($('#m_gmap_address').val());
|
||||||
where: query,
|
GMaps.geocode({
|
||||||
callback: function (r) {
|
address: text,
|
||||||
// clear map
|
callback: function(results, status) {
|
||||||
map.entities.clear();
|
map.entities.clear();
|
||||||
// Add the first result
|
if (status == 'OK') {
|
||||||
if (r && r.results && r.results.length > 0) {
|
var location = results[0].geometry.location;
|
||||||
pin = new Microsoft.Maps.Pushpin(r.results[0].location, {
|
var lat = location.lat();
|
||||||
draggable: false,
|
var lng = location.lng();
|
||||||
icon: '/assets/images/icon-destination.png'
|
|
||||||
});
|
// show in map
|
||||||
map.entities.push(pin);
|
var loc = new Microsoft.Maps.Location(lat, lng);
|
||||||
map.setView({
|
pin = new Microsoft.Maps.Pushpin(loc, {
|
||||||
center: location
|
draggable: false,
|
||||||
});
|
icon: '/assets/images/icon-destination.png'
|
||||||
// set value in hidden input
|
});
|
||||||
$('#map_lat').val(locTemp.latitude);
|
|
||||||
$('#map_lng').val(locTemp.longitude);
|
map.entities.push(pin);
|
||||||
}
|
map.setView({
|
||||||
else {
|
center: loc
|
||||||
alert('wala');
|
});
|
||||||
|
|
||||||
|
// 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() {
|
$("#m_gmap_address").keypress(function(e) {
|
||||||
var text = $.trim($('#m_gmap_address').val());
|
var keycode = (e.keyCode ? e.keyCode : e.which);
|
||||||
if (!searchManager) {
|
if (keycode == '13') {
|
||||||
// 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) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
handleAction();
|
handleAction();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$("#m_gmap_address").keypress(function(e) {
|
|
||||||
var keycode = (e.keyCode ? e.keyCode : e.which);
|
|
||||||
if (keycode == '13') {
|
|
||||||
e.preventDefault();
|
|
||||||
handleAction();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue