【问题标题】:Invoke Google geocoder service from C#从 C# 调用 Google 地理编码器服务
【发布时间】:2014-02-15 03:47:00
【问题描述】:

在生成谷歌地图时,我将地址发送到 java 脚本函数。示例代码:--

java脚本功能代码:--

function codeAddress(address) {
        //            var address = document.getElementById("address").value;
        var address;
        geocoder.geocode({ 'address': address }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location
                });
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });

`" cs 代码:-- "

string addrs= "New York,USA";
 Page.ClientScript.RegisterStartupScript(this.GetType(), "a", "codeAddress(" + addrs + ");", true);

" 我正在使用正确的 API 密钥和 url。在 html 中它的工作。但是当我从cs文件传递地址时它不起作用。为什么?我如何通过传递地址值来执行上面的java脚本函数..代码有什么问题...谢谢

【问题讨论】:

  • codeAddress 不接受任何参数,但您在代码隐藏中传递了一个参数。
  • 我更新了我的代码,请检查
  • How to call google geocode service from c# code 的可能重复项(发现谷歌搜索“google map geocode c#” ...)
  • @Alex,你不觉得他的问题和 ASP.NET Web Forms 有关吗?
  • 在你的第一行codeAddress放置一个console.log(),看看你是否正在输入你的函数。

标签: javascript asp.net google-maps


【解决方案1】:

试试

Page.ClientScript.RegisterStartupScript(this.GetType(), "a", "codeAddress('" + addrs + "');", true);

我的猜测是它不会被解释为没有'' 的字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-18
    • 1970-01-01
    • 2013-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多