Google map api v3 markers exclude a city or certain bound - google-maps-api-3

I am using google maps api v3. I have a database of markers with lat and long address that I display on a map and that works fine.
The map is displaying markers for entire state and now I want to know how can exclude markers in a certain city? Say I am displaying a map of Indiana and want to exclude Indianapolis.
I have a rough idea where I can select the points and some how check if they are between a certain range but could someone elaborate on this with a more specific example or is there a better approach to this?

What you need is something called Reverse Geocoding, which will give you result of street name, city name and country name, given longitude latitude example.
I will do these steps :
Iterate all the marker and "reverse geocoding" the marker lat-long.
Check city result of the "reverse geocoding".
If the City is not inside your accepted cities, remove the marker.

Related

Get Lat/Long from City Auto Complete

I am using a plugin that provides a location field type (City/State/Country, etc) that uses the Google Maps API to autocomplete the field. I am using only the City field. It works as it should: start typing the city and the dropdown fills with possible city/country matches. Then I pick one. Is it possible to extract the lat/long coordinates from the selection made in the dropdown?
If so, how?

Here Fleet Telematics admin area

I am using fleet telematics and accessing tile for kuwait. If a place is present into two tiles I combine combine all coordinates from all rows for that place and convert that coordinates into polygon.
Please see the image below as i see weird polygons.
To get the city bounds of Kuwait city admin area, you may want to use ADMIN_POLY_8.
If you query that layer, you will notice that the ADMIN_LEVEL attribute here is '4' which corresponds to city.
To understand which layer to pick, check the description of the layer on sending this call
https://s.fleet.ls.hereapi.com/1/doc/layer.json?layer=ADMIN_POLY_8&apiKey={{RESTapiKey}}
In the response, you will see the attribute 'ADMIN_LEVEL' which says 'Administrative level 1 - 9.To look up the country specific name/meaning, applications can load the static table {COUNTRY} and fetch the value from column'
When you query the static layer 'COUNTRY' , you will see that 'ADMIN_LEVEL_DESCRIPTION_4' corresponds to city.
This is how you can find out which layer to choose.
you have selected ADMIN_POLY_9 which has places with ADMIN_LEVEL 5.
This gives you the geometric bounds of SETTLEMENT within the city and thus the multiple polygons.

Get country, county and street name from layers

currently we fetch the address information from reverse.geocoder but we are also using rme and pde so i was wondering if I can everything without reverse geocoder call?
What we need at the end is
STREET NAME, COUNTY, COUNTRY
Country and street name we have, but the county (federal state name) is only an id in ROAD_ADMIN_FC. Is there a way to map it to a name?
Geocoder API is the best to get street, county and country information all in one query. But depending on your usecase, you can also check out ROAD_NAME_FC* and ROAD_ADMIN_NAMES_FC* to get these information. Refer tcs.ext.here.com/pde/layers?region=WEU&release=18135&url_root=pde.api.here.com to check the responses you can get from these PDE layers.

Filter Google Places API results based on City

For one of my applications, I will let the users choose a City and then an Area. What I want to achieve is that based on the user's city selection, the Area field(which is using the autocomplete from Google Places) to display areas from that City. Eg: If user chooses the city as New York, the Area field should autocomplete only the areas from New York. Is this something which can be achieved?
1] In autocomplete API, pass the "Lat,Long" in "location" parameter and "100000" in "radius" parameter. It will bias search result within 100Km in that city.
Eg: Pass "40.7128,74.0059" for NewYork and it will give you result within 100Km in NewYork city.
OR
2] There is a trick you can use.If a user chooses a city, just add the city name as a prefix in the search string. It will only give the search suggestions in which the user is searching. eg, pass "NewYork" as a prefix in your search string, now type any word, it will only give you results for NewYork city restaurant, cafes, places, etc
You can do it by restricting the results of your autocomplete by a specified area.
Here are the ways that you can use:
Location Biasing - you may bias the results to a specified circle by passing a location and a radius parameter. This instructs the Place Autocomplete service to prefer showing results within that circle. Results outside of the defined area may still be displayed. You can use the components parameter to filter results to show only those places within a specified country.
Location Restrict - it can restrict the results to the region defined by location and a radius parameter, by adding the strictbounds parameter. This instructs the Place Autocomplete service to return only results within that region.
Places Types - you can restrict results from a Place Autocomplete request to be of a certain type by passing a types parameter. The parameter specifies a type or a type collection, as listed in the supported types below. If nothing is specified, all types are returned.
Hope this information helps you.

Select points within a country using google maps api

I have several markers plotted in a world map using google maps API.
I would like to click in a country and then delete all the other markers and only see the points within this country border. For example, if I click in Brazil I just wanna see the markers inside Brazil.
I also would like to get a list of lat-lngs of the points inside the country after clicking in the country.
Does anybody knows how can I do that?
Thanks in advance!
Maybe the most efficient way is, if you can, to add to all your markers the attribute of the country code where the marker belong to.
When a user click on the map, pass the given lat/long to Geoname webservice (for example, you can also use Google Geocoding API) to obtain the country code. Then loop over your marker array and keep all the desired markers.
To get lat long from a click and get the country code from Geoname:
google.maps.event.addListener(map, 'click', function( event ){
getCountryCode(event.latLng.lat(),event.latLng.lng());
});
function getCountryCode(latitude, longitude) {
$.getJSON('http://ws.geonames.org/countryCode', {
lat: latitude,
lng: longitude,
type: 'JSON'
}, function(result) {
console.log(result.countryCode);
}
}
If you're not able to append the country code to the markers attributes, you will have to work with polygons of each country and search that a point is in a polygon.
If so, maybe this extension could help you: https://github.com/tparkin/Google-Maps-Point-in-Polygon
And for polygons of each country, use a simple geometry like this one: https://github.com/johan/world.geo.json/tree/master/countries

Resources