I am not really finding a solution for this, probably it is quite easy: So first of all I get my JSON with the following code:
testApp.controller("cat0Controller", function($scope, $http){
var url = "../../../Data/JSONs/randomdata_cat0.json";
$http.get(url).then(function(response){
$scope.dataset = response.data;
$scope.hi = response.status;
});
});
Displaying the Json data with ng-repeat in a html table works fine.
The JSON looks something like this:
[
{
"Lat": 16.374,
"Long": 48.212,
"Timestamp": "2017-01-07 / 13:31:56",
"Downstream": 20.79852450876752,
"Upstream": 20.87613636972708,
"Category": 5
},
So now I want to get the Latutude and Longitude values and display at these positions the Google Maps markers with a onClick Text with the Upstream, Downstream and timestamp.
My current HTML and Google Maps code you can find below:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<script src="../js/speedtestTestController.js"></script>
<style type="text/css">
html { height: 50% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 40%; width: 40%; }
</style>
<script type="text/javascript">
function initialize() {
var mapOptions = {
zoom: 11,
center: new google.maps.LatLng(48.209500, 16.370691),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(48.209500, 16.370691),
animation:google.maps.Animation.Bounce,
map: map,
// icon: '../images/Speed.png'
});
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?key=AIzaSyBv_SRg4EiNNN8RJZeQ_y78h2j804msLPA&sensor=true&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
</script>
</head>
<body ng-app="testApp" >
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
Do you have a solution for dynamically generate such markers from the JSON data?
Thanks in advance!