I'm trying to Plot google map by getting the coordinates from database.
I've converted the data into JSON & trying to get locations from this JSON.
The JSON is:
[
{"GPS_COORDINATES":"29.392498333333332,71.69455666666666","TOWN":"T00031","LOCALITY":"107","SLOCALITY":"005","STATUS_DATE":"2017-09-16 00:00:00.000","TOTAL_SKU":"0"},
{"GPS_COORDINATES":"29.392564999999998,71.69445666666667","TOWN":"T00031","LOCALITY":"107","SLOCALITY":"005","STATUS_DATE":"2017-09-26 00:00:00.000","TOTAL_SKU":"1"},
{"GPS_COORDINATES":"29.400855,71.66181499999999","TOWN":"T00031","LOCALITY":"107","SLOCALITY":"005","STATUS_DATE":"2017-10-15 00:00:00.000","TOTAL_SKU":"1"}
]
I've tried the following code:
var ltlng = [];
var HiddenValue_gps_Coordinates = document.getElementById("<%=HF_gps_Coordinates.ClientID%>").value;
for (var i = 0; i < HiddenValue_gps_Coordinates.length; i++) {
var obj = HiddenValue_gps_Coordinates[i][0];
//ltlng.push(new google.maps.LatLng(obj.GPS_COORDINATES));
ltlng.push(new google.maps.LatLng(HiddenValue_gps_Coordinates[i][0]));
}
The JSON is set into the HiddenField by using C#
Reference to: JavaScript loop through json array? , I've tried the following code which is showing "undefined" in Console:
var HiddenValue_gps_Coordinates = document.getElementById("<%=HF_gps_Coordinates.ClientID%>").value;
for (var i = 0; i < HiddenValue_gps_Coordinates.length; i++)
{
var obj = HiddenValue_gps_Coordinates[i];
console.log(obj.GPS_COORDINATES);
ltlng.push(new google.maps.LatLng(HiddenValue_gps_Coordinates[i][0]));
}
This is not working for me. Please Help
UPDATE:
The following code retrieved the coordinates very fine & print them to Console:
var HiddenValue_gps_Coordinates =JSON.parse(document.getElementById("<%=HF_gps_Coordinates.ClientID%>").value);
for (var i = 0; i < HiddenValue_gps_Coordinates.length; i++)
{
var obj = HiddenValue_gps_Coordinates[i];
console.log(obj.GPS_COORDINATES);
//The following is not working
ltlng.push(new google.maps.LatLng(obj.GPS_COORDINATES));
}
This is the snapshot of the Console:
But still I'm unable to plot the markers on Google map by using these Coordinates.
Please Help