Search name region/city php

Asked

Viewed 138 times

2

I am using Yahoo’s Weather API. The point is I want the time to be displayed for the user’s location.

Considering I’m wearing the following:

$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select item from weather.forecast where woeid in (select woeid from geo.places(1) where text="Lisbon, pt")';

$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json&u=c";

Everything works very well, but in this case it returns the time to Lisbon, pt (The location is set in the query).

I want to go from php to fetch the user’s location, but if it is by IP, it returns the location of the internet service, which means that it is not where the user is actually. Is there another way to control this? I’ve already been able to search for javascript, but I can’t use a javascript variable in PHP.

  • you need to get the ip of the place where you are , with the ip you know the geographical location.

  • https://www.mylesgray.com/software/use-geolocation-get-user-location-weather-ip-address/

  • @user2964140, the ip I am in does not. As I mentioned, the ip is from my internet provider, which is in a different location. But thanks anyway

  • just so you can...you can have an array of locations and force...

1 answer

1

There is no automatic way to find out the precise location of the user, unless asking for it ;)

You can get the user’s approximate location through their IP address. You can use a service such as http://ipinfodb.com/my_ip_location.php to retrieve location data via IP.

  • yes, but by javascript we were able to ask for the browser’s location, asking the user. This is not possible in php?

  • 1

    No. PHP runs on the server. Javascript runs on the browser. The localization functionality is from the browser, so only with Javascript you can get it. What can be done is to get via JS and pass to PHP (for example, via Ajax).

  • That’s a good idea. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.