Форум программистов, компьютерный форум, киберфорум
JavaScript: API
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
0 / 0 / 0
Регистрация: 24.02.2015
Сообщений: 1
1
Google API

Передвижение маркера на google maps с переменной скоростью

24.02.2015, 13:08. Показов 1170. Ответов 0
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Дорогие друзья, я начинающий программист на JavaScript, мне очень нужна ваша помощь: я взялся за проект где я должен показывать как будет двигаться обьект(машина) по заданной мной траектории(я задаю кординаты передвижения lat i long). Только, проблема в том что машина должна двигаться не с равномерной скоростью а с переменной (т.е не двигаться равномерно а в некоторой части ускорятся либо замедлятся и чтоб я мог задавать на какой промежутке пути ускорятся (и насколько) или замедлятся) Как это сделать? .А также подскажите пожалуйста, что в моем коде определяет count из animateCircle() и что означает icons[0].offset = (count / 2) + '%'; ? Полный код программы привожу внизу(файл координат передвижения js файл - вложено):
PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html>
<head>
<title>Spotlight </title>
<meta charset="UTF-8"> 
 
 
<style>
header {font-family:Georgia,"Times New Roman",serif;
    font-size:16px;
    display:block; }
canvas {position:absolute; top: 165px; left:0px; z-index:100;}
#place {position:absolute; top: 165px; left: 0px; z-index:1;}
body {
    background-color: orange;
    background-size:100%; 
}
 
 
 
</style>
 
 
<script type="text/javascript" charset="UTF-8" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript" charset="UTF-8" src="coordinates(Kiel-Berlin).js"></script>
<script type="text/javascript" charset="UTF-8">
var locations = [
        [54.31432029,10.10394573, "Kiel-Berlin"],
        [54.31432029,10.10394573,"Kiel-Hamburg"],
        [52.51925017,13.40353489,"Berlin-Lubeck"]
        ];
    
        
var positionopts;
positionopts = {
    enableHighAccuracy: true} ;
var candiv;
var can;
var ctx;
var pl;
 
function init() {
    var mylat;
    var mylong;
 candiv = document.createElement("div");
 candiv.innerHTML = ("<canvas id='canvas' width='600' height='400'>No canvas </canvas>");
 document.body.appendChild(candiv);
 can = document.getElementById("canvas");
 pl = document.getElementById("place");
  ctx = can.getContext("2d");
can.onmousedown = function () { return false; } ;  //prevents change of cursor to default
   
   can.addEventListener('mousedown',pushcanvasunder,true);
   can.addEventListener("mouseout",clearshadow,true);
   mylat = locations[0][0];
   mylong = locations[0][1];
   makemap(mylat,mylong);
 
 
}
function pushcanvasunder(ev) {
    can.style.zIndex = 1;
    pl.style.zIndex = 100;
}
 
function clearshadow(ev) {
    ctx.clearRect(0,0,600,400);
}
 
 
 
 
var listener;
var map;
var blatlng;
var myOptions;
 
 
var rxmarker = "x1.png";
 
 
function makemap(mylat,mylong) {
    var marker;
 blatlng = new google.maps.LatLng(mylat,mylong);
 
myOptions = {
      zoom: 6,
      center: blatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
      //disableDefaultUI: true
    };
map = new google.maps.Map(document.getElementById("place"), myOptions);
//mark center
marker = new google.maps.Marker({
                                     position: blatlng,
                                     title: "center",
                                     icon: rxmarker,
                                     map: map });
 
 
 
//CODE FOR MOVING THE CIRCLE
 
 
  // Define the symbol, using one of the predefined paths ('CIRCLE')
  // supplied by the Google Maps JavaScript API.
  var lineSymbol = {
    path: google.maps.SymbolPath.CIRCLE,
    scale: 8,
    strokeColor: '#11BDBA'
  };
 
  // Define the symbol, using one of the predefined paths ('CIRCLE')
  // supplied by the Google Maps JavaScript API.
  var lineSymbol = {
    path: google.maps.SymbolPath.CIRCLE,
    scale: 8,
    strokeColor: '#3F35B0'
  };
 
  // Create the polyline and add the symbol to it via the 'icons' property.
  line = new google.maps.Polyline({
    path: lineCoordinates,
    icons: [{
      icon: lineSymbol,
      offset: '100%'
    }],
    map: map
  });
 
  animateCircle();
 
}
 
 
// Use the DOM setInterval() function to change the offset of the symbol
// at fixed intervals.
function animateCircle() {
    var count = 0;
    window.setInterval(function() {
      count = (count + 1) % 200;
 
      var icons = line.get('icons');
      icons[0].offset = (count / 2) + '%';
      line.set('icons', icons);
  }, 400);
  
}
 
 
function round (num,places) {
    var factor = Math.pow(10,places);
    var increment = 5/(factor*10);
    return Math.floor((num+increment)*factor)/factor;
    
}
 
 
function changebase() {
    var mylat;
    var mylong;
    for(var i=0;i<locations.length;i++) {
        if (document.f.loc[i].checked) {
            mylat = locations[i][0];
            mylong = locations[i][1];
            makemap(mylat,mylong);
            document.getElementById("header").innerHTML = "Base location is set to the route "+locations[i][2];
        }
    }
    
    return false;
}
</script>
</head>
<body onLoad="init();">
<header id="header">Base location (Kiel-Berlin by default)-Please change below: </header>
<div id="place" style="width:600px; height:400px"></div>
 
 
<div id="answer"></div>
Change base location: <br/>
<form name="f" onSubmit=" return changebase();">
 <input type="radio" name="loc" /> Kiel-Berlin<br/>
 <input type="radio" name="loc" /> Kiel-Hamburg<br/>
 <input type="radio" name="loc" /> Berlin-Lubeck<br/>
 
<input type="submit" value="CHANGE">
</form>
</body>
</html>
Вложения
Тип файла: rar coordinates(Kiel-Berlin).rar (17.6 Кб, 1 просмотров)
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
24.02.2015, 13:08
Ответы с готовыми решениями:

Расположение описания маркера в google maps
Здравствуйте. В интернетах не нашел ответа на вопрос, как расположить описание маркера в...

Привязка маркера к камере в google maps
Нужно сделать так что бы маркер добавленый на карту двигался вместе с камерой как вот здесь :...

Несколько snippet для маркера Google Maps v.2
Пользуюсь картами Google Maps v.2, там маркер добавляется вот так markerOptions = new...

Разные drawable для маркера Google Maps
Здравствуйте. Есть код главной активити @Override public void onCreate(Bundle...

0
24.02.2015, 13:08
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
24.02.2015, 13:08
Помогаю со студенческими работами здесь

Как подключить географические карты типа Google Maps или Open street maps в своё приложение
Всем доброго времени суток. Вопрос такой: как подключить географические карты типа Google Maps или...

Передвижение спрайтов с разной скоростью
Проблема в следующем, что имеем 2 многоугольника, у одного скорость 0.5, у второго 1. На деле имеем...

Google сделала браузерную версию Google Maps трехмерной
Интернет-гигант Google вчера представил обновление для сервиса Google Maps. Компания показала новую...

Google Maps 2. Ограничение на количество запросов к google
Google накладывает ограничение на количество запросов в день к Google Maps (2500 в день на ключ)....


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
1
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru