Is there any way of utilizing maxmind in order to get city codes via the IP of the user ?
In the following example, I am able to get the name of the City but not cityCodes. As far as I know maxmind does not have a support for city codes ;
Ref for maxmind support : https://www.maxmind.com/en/geoip2-city
E.g;
private static DatabaseReader reader = null;
InetAddress inetAddress = InetAddress.getByName(ipAddress);
CityResponse response = reader.city(inetAddress);
String cityName = response.getCity().getName(); //Istanbul
String cityCode = response.getCity().???code???; // The desired output : IST
As far as I am aware, the UN/LOCODE is the closest match to what you are asking for. MaxMind itself does not provide these codes in its data set, but it does provide a geoname_id for the city that can be used to look up the city in the GeoNames data set. GeoNames provides UN/LOCODE in their premium data set.
Related
In Amadeus API the is often a reference to "cityCode"
The documentation give this example
https://test.api.amadeus.com/v2/shopping/hotel-offers?cityCode=PAR&adults=1&radius=5&radiusUnit=KM&paymentPolicy=NONE&includeClosed=false&bestRateOnly=true&view=FULL&sort=PRICE
Where is the list of ALL cityCode ???
for this example it seems PAR refers to PARIS
is this https://service.unece.org/trade/locode/fr.htm
is there a cvs format of all city codes ?
Thanks
You can use the Airport & City Search API to find an IATA code based on a city name
Otherwise, this website provides a list of IATA city codes.
Given that I have a model denoting a city which holds a collection of streets.
public class City {
public int Id { get; set; }
public string Name { get; set; }
public IEnumerable<Street> Streets { get; }
}
public class Street {
public int Id { get; }
public string Name { get; }
public IEnumerable<Building> Buildings { get; }
}
If a client is interested in all cities (api/cities/all) and I'd return him the full collection, this would lead to a massive response, depending on the size of the dataset. So I thought first about returning only street ids inside the streets collection. This however feels awkward because while the ids might be useful to further fetch the streets, they hold no meaningful value for a client (it doesn't make sense to populate a list of ids on a view in order to show what streets are in a city, doesn't it?).
My next idea was to ditch the streets collection completely and instead offer an API endpoint to fetch the streets of a city:
api/cities/3737/streets
That way I can fetch a complete list of streets, however the returned data then doesn't contain any information to where the streets belong to. If I a client now wants to show both the streets and the city, he'd have to make 2 API calls to get the information he needs.
What is a common way to return such data?
I would create 2 city objects, a city object containing only the basic data(like ID & Name) and a cityDetail object containing all the data (including the full street plan).
Depending on your situation you might repeat this pattern for the buildings.
You can then return the city object in your list call and only if a get by id is performed you would return the cityDetail object.
The bad => your api is sorta "inconsistent" as the city objects you get via a list are not the same as the ones you get via the get. You could make 2 resources: city & cityDetail with cityDetail not having a List function and city not having a getByID function but still it's not as clean & predictable as a single resource.
The good => Performance wise & usage wise this usually is a perfect match. You will never show a list of cities with streets so the city object would be sufficient. When you are viewing a single city it is very likely you want to show all data including streets(or at least use this data on that page) so the cityDetail object would fit here as well.
Performance wise it's kinda obvious that fetching 1 milion streets for a getAllMyCities call is overkill ;)
I have a site where user A can book a lesson with a teacher, I then want to have an email sent to the teachers saying user A wants to book a lesson with you etc.
I have postal up and running sending emails without issue,
however, I don't know how to access the email address of the teacher to send the email.
The email address is saved as part of the built in UserProfile table. I have the teacher's UserId (as it's stored in a separate teacher table).
So is there a way to access the teachers email ,searching by UserId?
In any other table I would use t in db.Teacher.find(id) but this doesn't work within the Account Controller.
This was built using the default MVC4 internet website template using the built in simple membership. Let me know if more information is needed.
I've added the following to the AccountController;
private UsersContext db = new UsersContext();
public ActionResult EmailNotification(int id)
{
var user = from l in db.UserProfiles.Find(id)
select l;
}
db.UserProfiles.Find(id) however gives the following error;
Could not find an implementation of the query pattern for source type 'LessonUp.Models.UserProfile'. 'Select' not found.
Which I assume is a result of it not being created through the entity framework?
I think your query needs to be something like the following:
var result = from q in context.UserProfiles
where q.UserId == id
select q;
few month ago i write something to get the latitude or longitude from google API. latter i get the database from drupal for latitude or longitude to most of city in worlds.
but the problem is that the same city name can be found two or more times in a area. like Firozabad in India and bangladesh both. Agra in UP and agar in Rajasthan.
means the confusion in name by user if they found two city by same name they are confused.
i hear that HTML 5 support latitude or longitude of the visiter but i need latitude or longitude where they are born or city they want to use to fill a form.
how i can get the latitude or longtiude from API like google and some other.
the process is that:
user put the location in textbox for getting their latitude or longitude.
for right thing i want to show them all location [if same thing found more then one].
they can choose the right location and after click they can get the lati and langitude.
how i can do this using any API.
If I understood you correctly then here's a Javascript function that returns a list of actual locations based on the address (full or partial) that user has entered:
getLocationsByAddress = function(address, onComplete) {
var geocoder = null;
var locations = [];
var location = null;
geocoder = new GClientGeocoder();
geocoder.getLocations(address, function(response) {
if (!response || response.Status.code != 200) {
if (typeof (onComplete) != 'undefined') {
onComplete([]);
}
} else {
for (var i = 0; i < response.Placemark.length; i++) {
location = response.Placemark[i];
locations[locations.length] = {
address: location.address,
x: location.Point.coordinates[1],
y: location.Point.coordinates[0],
zoom: 14
}
}
if (typeof (onComplete) != 'undefined') {
onComplete(locations);
}
}
});
}
The code uses API version 2 but I think it should be fairly easy to make it work with V3 (please see this API reference for details).
UPDATE
As #Maxym stated the V2 API is considered as deprecated and therefore shouldn't be used any further.
Take a look at this jQuery plugin. It claims to work with both V2 and V3 so you may want to examine the source code in order to find out how they do an it with V3.
I am not sure that it is about HTML 5. You just need to create sort of hints, where user can select which exactly city she means (the way Google does on maps.google.com - you enter "Odessa" and see list of cities with such name). Google has geocoder API but probably it should be used with Google Map (just read license).
So the process is easy: user enters city, you send it to geocoder to get list of cities with such a name and their coordinates. THen you show that list, user selects one and you have its coordinates.
There is documentation how to use Geocoding API v3 in JavaScript, as well as examples. This one show how to get coordinates from address, take into account that they process results[0] only, but you need to iterate over results to get all cities.
I want to parse the addresses from Google geocoding API and store it as:
address
city
state
zipcode
country
Some places has full address from Google map and some just half, how can i know which part of the address is city, state or country? or just zipcode?
It would be helpful if some expert pointed out some help here.
In the response the geocoding API breaks up the address into AdministrativeAreaName (usually State) and SubAdministrativeArea. The SubAdministrativeArea area includes LocalityName (City), PostalCodeNumber (Zip Code) and Thoroughfare (Street Name and Number). For an example see: http://maps.google.com/maps/geo?q=1%20Infinite%20Loop,%20Cupterino,%20Ca. This is a geocode requst for Apple's Headquarters which has an address of 1 Infinite Loop, Cupterino, CA 95014.