Afficher des marqueurs dans GoogleMaps à partir d'un base de données
Bonjour à tous
Voici mon problème ...
Je voudrais à partir des données contenues dans ma base de données afficher des marqueurs dans une carte google map
Voici mon code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
function initMap() {
var myLatLong = new google.maps.LatLng(57.9, 14.6);
var mapOptions = {
zoom: 6,
center: myLatLong,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'),
mapOptions);
for (var i = 0, length = json.length; i < length; i++) {
var data = json[i],
latLng = new google.maps.LatLng(data.lat, data.lng);
// Creating a marker and putting it on the map
var marker = new google.maps.Marker({
position: latLng,
map: map,
title: data.title
});
} |
et mes données en format JSON
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| var json = [
{
"title": "Stockholm",
"lat": 59.3,
"lng": 18.1,
"description": "Stockholm is the capital and the largest city of Sweden and constitutes the most populated urban area in Scandinavia with a population of 2.1 million in the metropolitan area (2010)"
},
{
"title": "Oslo",
"lat": 59.9,
"lng": 10.8,
"description": "Oslo is a municipality, and the capital and most populous city of Norway with a metropolitan population of 1,442,318 (as of 2010)."
},
{
"title": "Copenhagen",
"lat": 55.7,
"lng": 12.6,
"description": "Copenhagen is the capital of Denmark and its most populous city, with a metropolitan population of 1,931,467 (as of 1 January 2012)."
}
]; |
Je ne m'y connais pas trop en Ajax mais j'aimerais passer ces paramétres à ma fonction.
Dans ma vue MVC je remonte les informations en format JSON
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
public JsonResult GetData()
{
var db = new BeparkDataContext();
var results = from cust in db.tb_markers
select new
{
AddresssLAt = cust.MarkerLat,
Addresssong = cust.MarkerLong,
};
return Json(results.ToList());
} |
Mais là je cale je ne vois pas comment à partir de là transferer les données remonté en JSON à ma fonction javascript
Merci d'avance