钛 - 添加数字时的问题

发布于 2024-12-21 13:39:16 字数 767 浏览 6 评论 0原文

我使用forwardGeocoder 获取纬度值,并将获得的纬度值与十进制数相加。看看下面的代码。

Ti.Geolocation.forwardGeocoder(textField.value, function(e) {
            var a = e.latitude;
            var b = 0.1;
            var c = a+b;
            Ti.API.info('result c:  '+c);
});

结果显示

[INFO] result c:  40.7145500.1

问题是,给定的值没有添加到纬度值中,它只是与字符串一起打印。

当我尝试减法时,效果很好。当我尝试使用 ab 的自定义值时,效果很好。

Ti.Geolocation.forwardGeocoder(textField.value, function(e) {
            var a = 0.1;
            var b = 0.1;
            var c = a+b;
            Ti.API.info('result c:  '+c);
});

结果显示

[INFO] result c:  0.2

那么,如何在获得的纬度上添加一个数字呢?帮我解决这个问题。提前致谢。

I am getting a latitude value using forwardGeocoder and I am adding the obtained latitude value with a decimal number. Have a look at the below code.

Ti.Geolocation.forwardGeocoder(textField.value, function(e) {
            var a = e.latitude;
            var b = 0.1;
            var c = a+b;
            Ti.API.info('result c:  '+c);
});

The result shows

[INFO] result c:  40.7145500.1

The problem is, the given value is not added to the latitude value, it is just printed along with the sting.

When I tried subtraction, it worked fine. When I tried using custom values for a and b, it worked fine.

Ti.Geolocation.forwardGeocoder(textField.value, function(e) {
            var a = 0.1;
            var b = 0.1;
            var c = a+b;
            Ti.API.info('result c:  '+c);
});

The result shows

[INFO] result c:  0.2

So, how could I add a number to the obtained latitude? Help me to solve this issue. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱你不解释 2024-12-28 13:39:16

看起来 e.latitude 是一个字符串,JavaScript 正在将 Number 转换为字符串并将其连接起来。

试试这个:

Ti.Geolocation.forwardGeocoder(textField.value, function(e) {
            var a = parseFloat(e.latitude);
            var b = 0.1;
            var c = a+b;
            Ti.API.info('result c:  '+c);
});

It looks like e.latitude is a string, and JavaScript is converting the Number to a string and concatenating it.

Try this:

Ti.Geolocation.forwardGeocoder(textField.value, function(e) {
            var a = parseFloat(e.latitude);
            var b = 0.1;
            var c = a+b;
            Ti.API.info('result c:  '+c);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文