Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1046387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:08:19+00:00 2026-05-16T16:08:19+00:00

I am trying to use an http request to google maps to obtain the

  • 0

I am trying to use an http request to google maps to obtain the driving distance between two locations using JSON. However, it seems these are treated different in a browser than in the (iphone) app.

I create an NSString which holds the URL, using coordinates and %20 (a space). I NSLog() the URL to make sure, and it seems ok (ie it works fine in browser and looks fine)…but when NSLogging the string initialised with the contents of that URL, I get (null).

Here is the code:

NSString *urlString=[[NSString alloc] initWithFormat:@"http://maps.google.com/maps/nav?q=from:%.7f%@%.7f%@to:%.7f%@%.7f", testLocation.coordinate.latitude, @"%%20", testLocation.coordinate.longitude, @"%%20", thePark.coordinate.latitude, @"%%20", thePark.coordinate.longitude];

which I then NSLog() and get http://maps.google.com/maps/nav?q=from:51.4986110%20-0.1236110%20to:51.4960938%20-0.2200041 …to no avail.

NSString *json=[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]];

When I NSLog() this, it prints null. Does anyone have any suggestions as to why this might be happening or an easier way to do it? I plan to then parse the JSON and get the drving distance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:08:20+00:00Added an answer on May 16, 2026 at 4:08 pm

    You should escape the urlString using “stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding” instead of escaping manually with %20.


    Edit:

    I tested with these 3 lines of codes and I got the json string.

    NSString *urlString=[[[[NSString alloc] initWithFormat:@"http://maps.google.com/maps/nav?q=from:%.7f %.7f to:%.7f %.7f", 51.4986110, -0.1236110, 51.4960938, -0.2200041] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] autorelease];
    
    NSString *json=[[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]] autorelease];
    NSLog(@"json = %@", json);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how make a basic GET request using Network.HTTP.simpleHTTP that
I'm trying to create a use-once HTTP server to handle a single callback and
I am trying to read the authorization header for an HTTP request (because I
I am trying to get my Django app (NOT using Google app engine) retrieve
Question: I'm trying to use JSON accross domains, but all i find is JSON
I am trying to use django-socialauth ( http://github.com/uswaretech/Django-Socialauth ) for authenticating users for my
I'm trying to use file_get_contents() to grab a twitter feed, however I'm getting the
I am trying to post a request to the google authSub for youtube. I
I am trying to learn how to use the Google Spreadsheets API through the
I am trying to use the Google Elevation API with the getJSON function of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.