0

在谷歌搜索如何在谷歌地图 v3 上旋转自定义标记图像 4-5 小时后,我在这里发布了这个问题。请通过示例提出任何解决方案。

4

3 回答 3

2

Code byuser1884506非常有用,但它会旋转默认图标。

您无法旋转自定义图像。参考 https://developers.google.com/maps/documentation/javascript/3.exp/reference#Symbol

符号的路径,即内置符号路径,或使用 SVG 路径表示法表示的自定义路径。必需的。

为此,您需要使用 SVG(可缩放矢量图形)创建图像。

于 2013-10-01T08:20:21.437 回答
1

请参考以下代码

<script type="text/javascript" >
function kh(i, j, k) {
    var a;
    var b;
    if (j != null && k != null) {
        a = j;
        b = k;
    }
    else {
        a = 12.9540112248064; b = 77.6991748809814;
    }
    if (i != null) {
        var angleDegrees = i;
    }
    else {
        angleDegrees = 0;
    }
    var angle = 45;


    var myLatlng = new google.maps.LatLng(a, b);
    var mapOptions = {
        zoom: 16,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    var arrowIcon = new Image();
    arrowIcon.src = "../Image/CarNew.png";
    var image = '../Image/add.jpg';
    var myLatLng = new google.maps.LatLng(a, b);
    var beachMarker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: {
        path: google.maps.SymbolPath.FORWARD_OPEN_ARROW,
scale: 2,
rotation: angleDegrees           }    

     });document.getElementById("HiddenField1").value=a;


document.getElementById("HiddenField2").value = b;
}
于 2012-12-07T06:22:53.260 回答
-5
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;


public partial class NewFolder1_Rotatev3 : System.Web.UI.Page
{
string line;
System.IO.StreamReader file = null;
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        file = new System.IO.StreamReader("D:\\GoogleMapsDemo\\Files\\closepoints.txt");
        ScriptManager.RegisterStartupScript(Page, typeof(Page), "_ShowHideBusiJust_", "i();", true);
        Session["file"] = file;
    }
}
protected void Timer1_Tick(object sender, EventArgs e)
{
    file = (System.IO.StreamReader)Session["file"];
    string[] strdata = null;
    line = file.ReadLine();
    if (line != null)
    {
        strdata = line.Split('\t');
        string j = strdata[0];
        string k = strdata[1];
        Session["Lat"] = j;
        Session["Long"] = k;
        int R = 6371; // km
        double lat1 =HiddenField1.Value != null ? Convert.ToDouble(HiddenField1.Value) : 0;
        double lat2 = Convert.ToDouble(j);
        double lon1 = HiddenField2.Value != null ? Convert.ToDouble(HiddenField2.Value) : 0;
        double lon2 =Convert.ToDouble(k);
        if (!(lat2 == 0 && lon2 == 0))
            {

            var dLat = DegreeToRadian((lat2 - lat1));
            var dLon = DegreeToRadian((lon2 - lon1));
            lat1 = DegreeToRadian(lat1);
            lat2 = DegreeToRadian(lat2);
            var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
            Math.Sin(dLon / 2) * Math.Sin(dLon / 2) * Math.Cos(lat1) * Math.Cos(lat2);
            var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
            var d = R * c;
            var y = Math.Sin(dLon) * Math.Cos(lat2);
            var x = Math.Cos(lat1) * Math.Sin(lat2) -
                    Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(dLon);
            var brng = (Math.Atan2(y, x));
            var last = RadianToDegree(brng);
            Label2.Text = Convert.ToString(d);
            string i = Convert.ToString(last);
            Session["Angle"] = i;
            string script = string.Format("i({0},{1},{2});",
                              i.ToString(), j.ToString(), k.ToString());
        ClientScript.RegisterStartupScript(this.GetType(), "RefreshOpener", script, true);
        //System.Threading.Thread.Sleep(1000);
        //strdata[0]   - Latitude
        //strdata[1]   - Langitude
            }

    }
    else
    {
        string i = Convert.ToString(Session["Angle"]);
        string j = Convert.ToString(Session["Lat"]);
        string k = Convert.ToString(Session["Long"]);
        string script = string.Format("i({0},{1},{2});",
                              i.ToString(), j.ToString(), k.ToString());
        ClientScript.RegisterStartupScript(this.GetType(), "RefreshOpener", script, true);
        Timer1.Enabled = false;

    }
    Session["file"] = file;
}
 private double DegreeToRadian(double angle)
{
    return Math.PI * angle / 180.0;
}
private double RadianToDegree(double angle)
{
    return angle * (180.0 / Math.PI);
}

}
于 2013-01-15T06:20:49.050 回答