、どのように私は、配列に項目を追加するには?各配列要素に複数の機能がある場合、どのように配列に追加するのですか?配列リストの各要素が複数の部品を持っている場合はHTMLで
は、私は、Googleマップのカスタムマップを作成していて、私は新しいアレイに座標を入力するフォームを使用しています。配列は座標位置のリストで、アイコンが関連付けられています。本文には、送信ボタンを使用してaddLocation関数を呼び出すヘッダーがあり、座標配列とマップも更新されます。アレイの操作が進む限り、これまでのところこのコードはありますか?任意のアイデアやヒント?これは私の基本的なもので、座標は単なる例です。
<html>
<head>
<title>Custom Markers</title>
<script>
var features =
[
{
position: new google.maps.LatLng(-33.91721, 151.22630),
type: 'starter'
},
{
position: new google.maps.LatLng(-33.91539, 151.22820),
type: 'unown'
}
];
function addLocation(coordinates)
{
features.push(***this is the part I'm not sure about***);
}
</script>
</head>
<body>
<div id="newlocation">
<p> Add a new location:</br>
<form action=addLocation(coordinates)>
Coordinates: <input type="text" name="coordinates"> <input type="submit">
</form>
</br>
</br>
</p>
</div>
<div id="map"></div>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 16,
center: new google.maps.LatLng(-33.91722, 151.23064),
mapTypeId: 'roadmap'
});
var iconBase = 'C:\Users\JM\Desktop\UnownMap\Icons\';
var icons = {
starter: {
icon: iconBase + 'starting.png'
},
unown: {
icon: iconBase + 'unownLoc.png'
}
};
// Create markers.
features.forEach(function(feature) {
var marker = new google.maps.Marker({
position: feature.position,
icon: icons[feature.type].icon,
map: map
});
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=___________&callback=initMap">
</script>
</body>
</html>
これは問題ありませんか?
あなたは「機能」オブジェクトへのあなたの座標要素から取得する方法を見つけ出す必要があります。要素からテキストを取得できますが、数値を解析してLatLngを構築する必要があります。 –