0

I am trying to get the long and lat of a user and then pull this in to a yahoo api query to get the WOEID based on this long and lat to then pass through to a weather API call.

My issue is that for minus longitudes the integer is returned e.g. -0.127683. The issue I have is in the following url call:

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.placefinder%20where%20text%3D%22"+lat+"%2C"+long+"%22&format=json&callback=

long includes the minus number but not in ASCII format as required by the URL call.

(long & lat in the above URL refers to the long and lat variables that have been pulled through in another AJAX call earler.)

Is there any work around?

Ian
  • 50,146
  • 13
  • 101
  • 111

1 Answers1

2

Simply call encodeURIComponent(str) on any piece going into the URL and it will be automatically converted to the URI safe format. See here on MDN for details.

jfriend00
  • 683,504
  • 96
  • 985
  • 979