admin管理员组文章数量:1403480
I'm making a Google Maps application where a user can search for a location. This location must point into the direction of a predefined marker.
Given the following pieces of code:
The predefined marker:
var station = new google.maps.LatLng(52.375401, 5.218824);
var stationMarker = new google.maps.Marker({
position: station,
map: map,
});
The marker that will be placed on the location that the user searched:
var direction = new google.maps.LatLng(52.376423, 4.887234);
var directionMarker = new google.maps.Marker({
position: direction,
map: map,
draggable: false,
title: "test"
});
directionMarker.setIcon(({
path: google.maps.SymbolPath.BACKWARD_CLOSED_ARROW,
scale: 6
}));
How can I make sure that the direction marker (i.e the marker from the user search result) always points to the predefined marker?
I'm making use of the Google Maps API v3.
I've created a jsFiddle, which you can find here
I'm making a Google Maps application where a user can search for a location. This location must point into the direction of a predefined marker.
Given the following pieces of code:
The predefined marker:
var station = new google.maps.LatLng(52.375401, 5.218824);
var stationMarker = new google.maps.Marker({
position: station,
map: map,
});
The marker that will be placed on the location that the user searched:
var direction = new google.maps.LatLng(52.376423, 4.887234);
var directionMarker = new google.maps.Marker({
position: direction,
map: map,
draggable: false,
title: "test"
});
directionMarker.setIcon(({
path: google.maps.SymbolPath.BACKWARD_CLOSED_ARROW,
scale: 6
}));
How can I make sure that the direction marker (i.e the marker from the user search result) always points to the predefined marker?
I'm making use of the Google Maps API v3.
I've created a jsFiddle, which you can find here
Share Improve this question edited Aug 14, 2014 at 9:54 Nazeem asked Aug 14, 2014 at 8:45 NazeemNazeem 7642 gold badges10 silver badges30 bronze badges 2- Can you create a jsfiddle? – MrUpsidown Commented Aug 14, 2014 at 9:17
- @MrUpsidown, yes. I've just added the jsFiddle: jsfiddle/fgdan8wq – Nazeem Commented Aug 14, 2014 at 9:54
1 Answer
Reset to default 6Ok here you go:
- Use the
google.maps.SymbolPath.FORWARD_CLOSED_ARROW
so that it points to the north. - Add the Geometry library to be able to pute a heading.
- Use the rotation parameter on your direction icon.
Here is how to pute the heading from your direction marker to the station:
var heading = google.maps.geometry.spherical.puteHeading(direction,station);
Then use it to rotate your icon accordingly:
directionMarker.setIcon({
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 6,
rotation: heading
});
You also had one unnecessary pair of ()
in the above code which I have removed.
JSFiddle demo
本文标签: javascriptLet arrow marker point in the direction of another markerStack Overflow
版权声明:本文标题:javascript - Let arrow marker point in the direction of another marker - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744396017a2604220.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论