How can I get a latitude and longitude of some location in asp.net MVC4?
For example how can I get the latitude and longitude of Hafeez center, Lahore, Punjab, Pakistan?
You can use the google GeoCoding service to convert an address to a set of coordinates.
For example for your address you would call:
http://maps.googleapis.com/maps/api/geocode/xml?address=Hafeez+center,Lahore,Punjab,Pakistan&sensor=false
My recommendation would be to do something like:
var responseDocument = XDocument.Load("http://maps.googleapis.com/maps/api/geocode/xml?address=Hafeez+center,Lahore,Punjab,Pakistan&sensor=false");
Then read the xml to the information you need.
Edited to add - make sure you check google's terms and conditions, they prohibit some types of applications!
Related
How do I know if there is a restaurant at a given lat-long location?
Can we use google maps/ google places/ Yelp/ FourSquare for the same?
Input : lat, long pair ( 1.280634,103.845392 )
Output : Meii Sushi
You could use the Foursquare API and search for venues at that location with the following request. Just pass your latitude & longitude in the ll param and set the radius around that point in meters in the radius param.
GET https://api.foursquare.com/v2/venues/search?ll=44.3,37.2&radius=200
With the categories field that is provided in the response you can check whether the place is a restaurant or not
I am working to get the latitude and longitude of nearest POI like airports, schools around a secondary latitude and longitude. So far i have searched and found the following API
http://maps.googleapis.com/maps/api/geocode/json?address=airport,Nashik&sensor=false
Unfortunately it works with the address instead of the secondary latitude and longitude. and if I insert the latitude and longitude it gives me the address of that point.
Is there a way to find the nearest airport(latitude,longitude) from the provided (latitude,longitude). I am trying this in PHP.
Please take a look at Google Places API
It's not that it fully meets your requirements and it has its limitations ("the maximum allowed radius is 50,000 meters", "radius must not be included" if you specify rankby = distance), but you can give it a try anyway.
Your requests could look like this
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.712784,-74.005941&rankby=distance&type=airport&key=<Your API Key>
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.712784,-74.005941&radius=50000&type=airport&key=<Your API Key>
You can use Aeris Weather api. Here's the documentation https://www.aerisweather.com/support/docs/api/reference/endpoints/places-airports/
You'd want to use closest action with largeairport filter to avoid smaller/non commercial/military airports
ex: https://api.aerisapi.com/places/airports/closest/p={lat,lng}&limit=5&radius=50miles&filter=largeairport&client_id={ID}&client_secret={SECRET}
You can query using other place params too https://www.aerisweather.com/support/docs/api/reference/places/
A PHP package for the api https://packagist.org/packages/mariohbrino/aeris
They have 6 months free trial and then its $23/month for basic plan.
I'm using google maps API to geocode a list of addresses detailed to street level (street, city, country).
One of the address I need to geocode is Niemcewicza, Warsaw, Poland the url I pass to curl is:
http://maps.googleapis.com/maps/api/geocode/json?address=Niemcewicza+Warsaw+Poland
but this is however returning the element which is of type bus_station, not a route type. Probably because the full street name is Juliana Ursyna Niemcewicza. I tried to use components and limit search to components=route:Niemcewicza but this resulted in ZERO_RESULTS. http://maps.googleapis.com/maps/api/geocode/json?address=Niemcewicza+Warsaw+Poland&components=route:Niemcewicza
Is there a way to obtain geocoding result of type route for not complete street names?
Try to use city & country as address and the known part of the street-name as route-component.
At least for the given example it works for me:
http://maps.googleapis.com/maps/api/geocode/json?address=Warsaw+Poland&components=route:Niemcewicza
I'm not very good at programming and just a beginner. My English is not that good, so I hope you can understand my question.
I'm interested to make a map like this but with a few modification: https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple
I have a mysql table with 3 columns: unit, lat, lng.
I want to make a map where user input the unit name, then it will look up for the value in mysql table, take the longitude latitude value, and display the address in google maps marker tooltips.
How do I do that? Thank you before!
You want to do this you need to learn webservices then only you can access you table.
Use this for restful webservice
using geocoder you can find the address corresponding lat and lag
use this website
I just discovered a strange behavior in Google Maps API V3, and more specifically with its Geocoding tool.
Here is an exemple : This is how I geocode my addresses :
var request = HttpWebRequest.Create(#"http://maps.googleapis.com/maps/api/geocode/json?address=" + address + "&sensor=false");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
where address is a varible with a full address entered by the user.
When the address is a valid one, response.StatusCode is OK, which means, according to the documentation, "that no errors occurred; the address was successfully parsed and at least one geocode was returned."
But when the try to geocode this adress :
15 StreetWhoDoesntExist, 69009 LYON
the StatusCode is OK and the latitude / longitude returned is the center of the city (in this example, LYON, which is a real French city and its corresponding zipcode, 69009).
Is this behaviour normal ? When I entered the same address in Google Maps, it told me it can't find this address (which is the "good" behavior). So, how can I reproduce it with GMaps API in order to it refuses addesses with an unknown street name, even if the associated city and/or zipcode exists ?
Thanks in advance !
API CALL
Result:
"partial_match" : true,
"types" : [ "sublocality", "political" ]
So I'd check those two or at least the types to determine if it found the actual street address.
Yes that is normal. There was a result returned, just not the one you were expecting. If you go a bit further down in the documentation you will see this:
geometry contains the following information:
location contains the geocoded latitude, longitude value. For normal address lookups, this
field is typically the most important.
location_type stores additional data about the specified location. The following values are
currently supported:
"ROOFTOP" indicates that the returned result is a precise geocode for which we have location information accurate down to street address precision.
"RANGE_INTERPOLATED" indicates that the returned result reflects an approximation (usually on a road)
interpolated between two precise points (such as intersections).
Interpolated results are generally returned when rooftop geocodes are
unavailable for a street address.
"GEOMETRIC_CENTER" indicates that the returned result is the geometric center of a result such as a
polyline (for example, a street) or polygon (region).
"APPROXIMATE" indicates that the returned result is approximate.
You will need to check the location_type to see how "accurate" the result returned is. In your case the geocoder was unable to find 15 StreetWhoDoesntExist, so the next best result was the center of the zipcode.
The address_components[] that are also returned with the geocode result has additional information you can use to get a better understanding of what is coming back.
The partial_match parameter will let you know if the geocoder did not return and exact match. This will ususally be true with misspellings or missing address parts.
The reason maps.google.com rejects the address is because they have custom logic built into their application that is catching these types of results. The geocoder just returns the raw result, you need to write business logic to handle those results.