Add geocoding to map. #221
This commit is contained in:
parent
e37406d6d1
commit
86963a2913
1 changed files with 27 additions and 16 deletions
|
|
@ -10,7 +10,8 @@ function GetMap()
|
||||||
{
|
{
|
||||||
map = new Microsoft.Maps.Map('#m_gmap', {
|
map = new Microsoft.Maps.Map('#m_gmap', {
|
||||||
center: new Microsoft.Maps.Location(14.6091, 121.0223),
|
center: new Microsoft.Maps.Location(14.6091, 121.0223),
|
||||||
culture: 'fil-Latn'
|
culture: 'fil-Latn',
|
||||||
|
zoom: 13
|
||||||
});
|
});
|
||||||
|
|
||||||
Microsoft.Maps.Events.addHandler(map, 'click', selectPoint);
|
Microsoft.Maps.Events.addHandler(map, 'click', selectPoint);
|
||||||
|
|
@ -30,29 +31,22 @@ function GetMap()
|
||||||
});
|
});
|
||||||
|
|
||||||
map.entities.push(pin);
|
map.entities.push(pin);
|
||||||
map.setCenter(location);
|
map.setView({
|
||||||
|
center: location
|
||||||
|
});
|
||||||
|
|
||||||
// set value in hidden input
|
// set value in hidden input
|
||||||
$('#map_lat').val(locTemp.latitude);
|
$('#map_lat').val(locTemp.latitude);
|
||||||
$('#map_lng').val(locTemp.longitude);
|
$('#map_lng').val(locTemp.longitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
map.setCenter(lat, lng);
|
|
||||||
|
|
||||||
// set value in hidden input
|
|
||||||
$('#map_lat').val(lat);
|
|
||||||
$('#map_lng').val(lng);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
|
|
||||||
function geocodeQuery(query) {
|
function geocodeQuery(query) {
|
||||||
var searchRequest = {
|
var searchRequest = {
|
||||||
where: query,
|
where: query,
|
||||||
callback: function (r) {
|
callback: function (r) {
|
||||||
// clear map
|
// clear map
|
||||||
map.entities.remove(pin);
|
map.entities.clear();
|
||||||
// Add the first result
|
// Add the first result
|
||||||
if (r && r.results && r.results.length > 0) {
|
if (r && r.results && r.results.length > 0) {
|
||||||
pin = new Microsoft.Maps.Pushpin(r.results[0].location, {
|
pin = new Microsoft.Maps.Pushpin(r.results[0].location, {
|
||||||
|
|
@ -60,19 +54,26 @@ $(function() {
|
||||||
icon: '/assets/images/icon-destination.png'
|
icon: '/assets/images/icon-destination.png'
|
||||||
});
|
});
|
||||||
map.entities.push(pin);
|
map.entities.push(pin);
|
||||||
map.setCenter(location);
|
map.setView({
|
||||||
|
center: location
|
||||||
|
});
|
||||||
// set value in hidden input
|
// set value in hidden input
|
||||||
$('#map_lat').val(locTemp.latitude);
|
$('#map_lat').val(locTemp.latitude);
|
||||||
$('#map_lng').val(locTemp.longitude);
|
$('#map_lng').val(locTemp.longitude);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
alert('wala');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
errorCallback: function (e) {
|
errorCallback: function (e) {
|
||||||
alert("No results found");
|
alert("No results found");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
alert(query);
|
||||||
|
searchManager.geocode(searchRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var handleAction = function() {
|
var handleAction = function() {
|
||||||
var text = $.trim($('#m_gmap_address').val());
|
var text = $.trim($('#m_gmap_address').val());
|
||||||
if (!searchManager) {
|
if (!searchManager) {
|
||||||
|
|
@ -81,6 +82,9 @@ $(function() {
|
||||||
searchManager = new Microsoft.Maps.Search.SearchManager(map);
|
searchManager = new Microsoft.Maps.Search.SearchManager(map);
|
||||||
geocodeQuery(encodeURIComponent(text));
|
geocodeQuery(encodeURIComponent(text));
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
map.entities.clear();
|
||||||
|
geocodeQuery(encodeURIComponent(text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,6 +101,11 @@ $(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
|
||||||
|
|
||||||
{% if ftags.set_map_coordinate %}
|
{% if ftags.set_map_coordinate %}
|
||||||
// check if we need to set map
|
// check if we need to set map
|
||||||
var location = new Microsoft.Maps.Location({{ obj.getCoordinates.getLatitude }}, {{ obj.getCoordinates.getLongitude }});
|
var location = new Microsoft.Maps.Location({{ obj.getCoordinates.getLatitude }}, {{ obj.getCoordinates.getLongitude }});
|
||||||
|
|
@ -109,7 +118,9 @@ $(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
map.entities.push(pin);
|
map.entities.push(pin);
|
||||||
map.setCenter(location);
|
map.setView({
|
||||||
|
center: location
|
||||||
|
});
|
||||||
|
|
||||||
// set value in hidden input
|
// set value in hidden input
|
||||||
$('#map_lat').val(locTemp.latitude);
|
$('#map_lat').val(locTemp.latitude);
|
||||||
|
|
@ -124,7 +135,7 @@ $(function() {
|
||||||
var hmap = new Microsoft.Maps.Map('#hub_map', {
|
var hmap = new Microsoft.Maps.Map('#hub_map', {
|
||||||
center: new Microsoft.Maps.Location({{ obj.getCoordinates.getLatitude }},
|
center: new Microsoft.Maps.Location({{ obj.getCoordinates.getLatitude }},
|
||||||
{{ obj.getCoordinates.getLongitude }}),
|
{{ obj.getCoordinates.getLongitude }}),
|
||||||
culture: 'fil-Latn';
|
culture: 'fil-Latn'
|
||||||
};
|
};
|
||||||
|
|
||||||
var dest = new Microsoft.Maps.Location({{ obj.getCoordinates.getLatitude }},
|
var dest = new Microsoft.Maps.Location({{ obj.getCoordinates.getLatitude }},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue