iphone NSString 的问题

发布于 2024-12-07 03:19:32 字数 1929 浏览 0 评论 0原文

我有一个 iPhone 应用程序,我想在其中绘制地图上两个位置之间的路线。位置由坐标(纬度、经度)引用。

为了加载这两个位置之间的路径点,我使用一个访问谷歌地图的脚本,使用以下方法:

function loadDirections(from, to, options) {
        gdir.load("from: " + from + " to: " + to, options);
    }

from应采用以下形式:46.777248,23.59989to 也像这样:44.437711,26.097367

换句话说,如果我像这样编写这个方法:

   function loadDirections(from, to, options) {

        gdir.load("from:46.777248,23.59989 to:44.437711,26.097367 ", options);
    }

一切都会顺利。

现在,进入我的 iPhone 应用程序......这就是我调用此方法的方式:

[directions loadWithStartPoint:startPoint endPoint:endPoint options:options];

- (void)loadWithStartPoint:(NSString *)startPoint endPoint:(NSString *)endPoint options:(UICGDirectionsOptions *)options {
    [googleMapsAPI stringByEvaluatingJavaScriptFromString:
     [NSString stringWithFormat:@"loadDirections('%@', '%@', %@)", startPoint, endPoint, [options JSONRepresentation]]];
}

换句话说,startPoint 应包含第一个位置的坐标,如下所示:

46.777248,23.59989 和 endPoint 应具有相同的形式。

因此,在我的 iPhone 应用程序中,我收到 startPoint 以及 endPoint 的纬度和经度,为了将它们放在请求的表单下,我有以下内容:

    NSString *startPoint;
        NSString *endPoint;

startPoint = [NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
endPoint = [NSString stringWithFormat:@"%@,%@", partenaire_lat, partenaire_lng];

但是当我通过此应用程序块调用 javascript。我

options.travelMode = UICGTravelModeDriving;
    [directions loadWithStartPoint:startPoint endPoint:endPoint options:options];

认为它不喜欢 startPointendPoint 的格式。

重要提示:当我使用 startPointendPointnull 值调用上述方法时,应用程序可以正常工作。

有人有什么想法吗? 我尽力解释得很清楚!!!!!我在这里以防有不清楚的地方!

I have an iphone application in which I want to draw the route between two locations on the map. The locations are refered by their coordinates(latitude, longitude).

For loading the waypoints between those two locations I use a script that acces google maps, with this method:

function loadDirections(from, to, options) {
        gdir.load("from: " + from + " to: " + to, options);
    }

from should be of this form: 46.777248,23.59989 and to also like this: 44.437711,26.097367.

In other words if I write this method like this:

   function loadDirections(from, to, options) {

        gdir.load("from:46.777248,23.59989 to:44.437711,26.097367 ", options);
    }

everything goes great.

Now, going into my iphone app....this is how I call this method:

[directions loadWithStartPoint:startPoint endPoint:endPoint options:options];

- (void)loadWithStartPoint:(NSString *)startPoint endPoint:(NSString *)endPoint options:(UICGDirectionsOptions *)options {
    [googleMapsAPI stringByEvaluatingJavaScriptFromString:
     [NSString stringWithFormat:@"loadDirections('%@', '%@', %@)", startPoint, endPoint, [options JSONRepresentation]]];
}

In other words, startPoint should contain the coordinates of the first location like this:

46.777248,23.59989 and endPoint should have the same form.

So in my iphone app I receive the latitude and longitude for the startPoint and also for the endPoint and in order to have them under the requested form I have this:

    NSString *startPoint;
        NSString *endPoint;

startPoint = [NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
endPoint = [NSString stringWithFormat:@"%@,%@", partenaire_lat, partenaire_lng];

But when I call the javascript through this

options.travelMode = UICGTravelModeDriving;
    [directions loadWithStartPoint:startPoint endPoint:endPoint options:options];

the app blocks.I assume it doesn't like the way startPoint and endPoint are formatted.

IMPORTANT: When I call the above method with null values for startPoint and endPoint the app works.

Anyone has any idea?
I did my best to explain it very clearly!!!!!I'm here in case something is unclear!

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

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

发布评论

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

评论(2

季末如歌 2024-12-14 03:19:32

我认为这可以解决您的问题,

NSString *startPoint;
NSString *端点;

startPoint = [NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
endPoint = [NSString stringWithFormat:@"%@,%@",partenaire_lat,partenaire_lng];

[起始点保留];
[端点保留];

I think this may solve your problem,

NSString *startPoint;
NSString *endPoint;

startPoint = [NSString stringWithFormat:@"%@,%@", latitudeString, longitudeString];
endPoint = [NSString stringWithFormat:@"%@,%@", partenaire_lat, partenaire_lng];

[startPoint retain];
[endPoint retain];

是伱的 2024-12-14 03:19:32

我认为这是因为您在坐标周围添加了单引号。当您在函数 loadDirections 中连接字符串时(假设这是一个 JavaScript 函数),这些内容会被保留。

另外,您的 loadDirections 中的 from: 和 to: 之后有一个空格,不知道这是否重要。

尝试

- (void)loadWithStartPoint:(NSString *)startPoint endPoint:(NSString *)endPoint options:(UICGDirectionsOptions *)options {
    [googleMapsAPI stringByEvaluatingJavaScriptFromString:
     [NSString stringWithFormat:@"loadDirections(%@, %@, %@)", startPoint, endPoint, [options JSONRepresentation]]];
}

I think it is because you are adding single quotes around the coordinates. These get preserved when you concatenate the strings in your function loadDirections (assuming that is a javascript function).

Also, you have a space after from: and to: in your loadDirections, don't know if that is important.

Try

- (void)loadWithStartPoint:(NSString *)startPoint endPoint:(NSString *)endPoint options:(UICGDirectionsOptions *)options {
    [googleMapsAPI stringByEvaluatingJavaScriptFromString:
     [NSString stringWithFormat:@"loadDirections(%@, %@, %@)", startPoint, endPoint, [options JSONRepresentation]]];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文