в google map Я пытаюсь показать местоположение своего пациента. Я могу получить свое местоположение пациента по этой функции, но я не знаю, как связать его со следующей функцией для показа моего пациента на карте Google.Как передать массив объекта в java-скрипт?
function getPoints() {
$.ajax({
type: "POST",
url: "Patient.asmx/GetPatient",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var Patientlocation = response.d;
$.each(Patientlocation, function (index, Patientlocation) {
$('#output').append('new google.maps.LatLng(' + Patientlocation.lat + ' ' + Patientlocation.lng + ')<br/>');
});
},
failure: function (msg) {
$('#output').text(msg);
}
});
}
это Google по умолчанию карту я должен передать объект на карту сверху функции к нему могли бы вы помочь
<script>
// This example requires the Visualization library. Include the libraries=visualization
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=visualization">
var map, heatmap;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: { lat: 34.0475, lng: -118.434 },
mapTypeId: google.maps.MapTypeId.SATELLITE
});
heatmap = new google.maps.visualization.HeatmapLayer({
data: getPoints(),
map: map
});
}
function toggleHeatmap() {
heatmap.setMap(heatmap.getMap() ? null : map);
}
function changeGradient() {
var gradient = [
'rgba(0, 255, 255, 0)',
'rgba(0, 255, 255, 1)',
'rgba(0, 191, 255, 1)',
'rgba(0, 127, 255, 1)',
'rgba(0, 63, 255, 1)',
'rgba(0, 0, 255, 1)',
'rgba(0, 0, 223, 1)',
'rgba(0, 0, 191, 1)',
'rgba(0, 0, 159, 1)',
'rgba(0, 0, 127, 1)',
'rgba(63, 0, 91, 1)',
'rgba(127, 0, 63, 1)',
'rgba(191, 0, 31, 1)',
'rgba(255, 0, 0, 1)'
]
heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
}
function changeRadius() {
heatmap.set('radius', heatmap.get('radius') ? null : 20);
}
function changeOpacity() {
heatmap.set('opacity', heatmap.get('opacity') ? null : 0.2);
}
// Heatmap data: 500 Points
function getPoints1() {
return [
new google.maps.LatLng(34.0482551, -118.434),
new google.maps.LatLng(34.0442551, -118.444),
new google.maps.LatLng(34.0422551, -118.454),
new google.maps.LatLng(34.0402551, -118.464),
new google.maps.LatLng(34.0502551, -118.474),
new google.maps.LatLng(34.0522551, -118.484)
];
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=visualization&callback=initMap">
</script>
здесь JsonFile
<ArrayOfPatientLocation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<PatientLocation>
<lat>34.0369842</lat>
<lng>-118.23060729999997</lng>
</PatientLocation>
<PatientLocation>
<lat>34.0369842</lat>
<lng>-118.22060729999997</lng>
</PatientLocation>
<PatientLocation>
<lat>34.0369842</lat>
<lng>-118.24060729999997</lng>
</PatientLocation>
<PatientLocation>
<lat>34.0369842</lat>
<lng>-118.24060729999997</lng>
</PatientLocation>
</ArrayOfPatientLocation>
присвоить результат в глобальной переменной и использовать этот вар, где вам нужно – scaisEdge
Нет! Не используйте глобальную переменную, особенно, чтобы не обрабатывать данные, возвращаемые из запросов AJAX! У вас будут бесконечные головные боли и вопросы времени. –
Помог ли мой ответ решить проблему? –