How to get city name from google map in ionic 2 - google-maps-api-3

How to obtain a city name from google map in ionic 2 If I have latitude and longitude coordinates of the area?
I searched all over the internet but I couldn't find the solution.

You can use Geociding, as explained in this thread from Ionic's forum
import { Geocoder, GeocoderRequest } from 'ionic-native';
let req: GeocoderRequest = { position: location }
Geocoder.geocode(req).then((results)=>{
})

You can find all you need about your location with this link. you can use geocode api as follow.
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY
just replace latlng by those you have and key by your API key found on google console.
Reminder: To use the Geocoding API, you must include an API key with all API requests and you must enable billing on each of your projects
more infos here.
https://developers.google.com/maps/documentation/geolocation/intro

Related

HERE LinkId from route not found in PDE (Platform Data Extension)

UPDATE: It's happening again, also with Fleet API. Please see additional examples at end of the post.
I'm using HERE's REST API to calculate a route, then ask for additional data for each link / route segment by querying HERE's Platform Data Extension (PDE). This usually works fine, but now I've run into a link id that is not recognised by PDE.
Are these services not in sync, or am I doing something wrong?
I didn't have any issue in the past weeks, and it still works fine for most link ids, so this could either be a new problem or a very singular issue. I searched in the HERE API documentation and on Stackoverflow, but couldn't find anything related.
Route request (A24 Berlin towards Hamburg): https://route.api.here.com/routing/7.2/calculateroute.json?waypoint0=geo!52.7091,13.0356&waypoint1=geo!52.7193,12.9608&mode=fastest;car;traffic:disabled&representation=navigation&app_id=xxx&app_code=yyy
The json response (below) contains a link with permanent id 1199057935 at Anschlussstelle Kremmen.
The PDE request gives an empty response: https://pde.api.here.com/1/index.json?layer=ROAD_GEOM_FCn&attributes=LINK_ID&values=1199057935&app_id=xxx&app_code=yyy
{"Layers":[]}
Instead, I would expect the data of the containing tile, e.g. what I get for 1199057936
{"Layers":[{"layer":"ROAD_GEOM_FC1","level":9,"tileXYs":[{"x":548,"y":405}]}]}
I also tried the PDE request with ROAD_GEOM_FC1 and prefixing the id with + (values=+1199057935). Other link ids of the route return the expected tile information.
For completeness, here's the link's json from the routing response:
{
"linkId":"+1199057935",
"shape":["52.7175629,12.976613","52.7177131,12.9749393"],
"firstPoint":28,
"lastPoint":29,
"length":114,
"remainDistance":1095,
"remainTime":39,
"nextLink":"+1199057936",
"maneuver":"M2",
"speedLimit":33.3333359,
"dynamicSpeedInfo":{"trafficSpeed":16.3888893,"trafficTime":7,"baseSpeed":27.5,"baseTime":4,"jamFactor":5.7118645},
"flags":["motorway"],
"functionalClass":1,
"roadNumber":"A24",
"timezone":"+0100",
"roadName":"",
"consumption":0,
"_type":"PrivateTransportLinkType"
}
UPDATE 2019-05-27:
I get a route that contains link id 1239826684 from https://route.api.here.com/routing/7.2/calculateroute.json?waypoint0=geo!52.5066,13.4299&waypoint1=geo!52.5282,13.4265&mode=fastest;car;traffic:disabled&representation=navigation&app_id=xxx&app_code=yyy
Using fleet endpoint redirects to same call as above, including link id 1239826684: https://fleet.api.here.com/2/calculateroute.json?waypoint0=geo!52.5066,13.4299&waypoint1=geo!52.5282,13.4265&mode=fastest;car;traffic:disabled&representation=navigation&app_id=xxx&app_code=yyy
PDE returns [] for that link id: https://pde.api.here.com/1/index.json?layer=ROAD_GEOM_FCn&attributes=LINK_ID&values=1239826684&app_id=xxx&app_code=yyy
Fleet API returns [] for that link id: http://fleet.cit.api.here.com/1/index.json?layer=ROAD_GEOM_FCn&attributes=LINK_ID&values=1239826684&app_id=xxx&app_code=yyy
Seems the underlying geo-data is not in sync, and using different APIs does not help. Any other solution?
You can try Fleet telematics group of API's over basic routing and PDE as Fleet Telematics provides whole routing solution .
Please find the below API request which is giving expected response for the id-1199057935
http://fleet.cit.api.here.com/1/index.json?layer=ROAD_GEOM_FCn&attributes=LINK_ID&values=1199057935&app_id=xxxx&app_code=yyyy
Response :
{
Layers: [
{
layer: "ROAD_GEOM_FC1",
level: 9,
tileXYs: [
{
x: 548,
y: 405
}
]
}
]
}
for more information kindly go through the below documentation
https://developer.here.com/documentation/fleet-telematics/api-reference.html#operation%2FindexJSONUsingGET
Hope this will help.

Restricting geocoding to a country

I have seen that it is possible with the "static" to limit the scope of the search to a certain area (with components restrictions), I have also seen that in release 3.exp (will be 3.14) of the JavaScript API, a new class google.maps.GeocoderComponentRestrictions has appeared. I have not seen anywhere how this class is supposed to be used though.
Does anyone have more information about this?
It looks like this was answered over at Google Maps Geocoding API, feature from the API missing in their JS api (?), with formatting like:
geocoder.geocode(
{ 'address': address, 'componentRestrictions':{'country':'GB'}},
function(results, status){
...
});
The GeocoderComponentRestrictions parameters get passed with the componentRestrictions key.

Store Locator API + Geolocation

I am trying to create a Store Locator with the Google API, very similar to the one in the Google examples here:
http://storelocator.googlecode.com/git/examples/panel.html
However I've hit a wall trying to get the Store Locator API to get the user's position through Geolocation, so when I click on Get Direction in the infowindow I get directions to the user position; instead of having to type my address in the: Where are you? Panel box.
In the documentation what I have seen is that geolocation is a boolean in the View Option that is set to True by default. But this does not solve my problem.
Does anyone have any idea on how to do this?
seems that the googlecode page you said is no longer exist. So I can't give any further insight about what you want to make.
However, by your description, Luckily I made similar site few months ago. It is on Grocery Store Near Me .
The concept of Geolocation is an HTML5 (actually W3C) Geolocation API which is now already embed in most modern browser. It is an API which you can obtain user's location (latitude, longitude, altitude, and accuracy).
you can call it with simply
navigator.geolocation.getCurrentPosition(success, error, geo_options);
Success and error is a callback function in which you can define.
In my case, the function looks like these
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
// use the lat and long to call function to fetch an API through AJAX
fetchStoreData(latitude, longitude);
}
In the Store Locator schema (like mine in Grocery Store Near Me), Geolocation is used to obtains user lat and long. The lat and long, then send to server via AJAX to get data about nearby store location.
The server serve an API in which accept lat and long as parameter, then fetch the store data (either using database, or other external API like foursquare), then you can display it either on list, or on a maps.

Can my code get the Google map API version number?

I am not using the v parm when I load the Google map API. Therefore I always get the "release" version of the API.
My app has an "About" feature and I would like to display the API version number.
Is there a way for me to get that value or would this be an enhancement request?
simply use: google.maps.version
http://jsfiddle.net/doktormolle/anN4U/
There was a way to get it from the filename of the script that loaded:
//*************************************************************
// API version from post on Google Maps API group by bratliff
var file,loop;
var tags=document.getElementsByTagName("SCRIPT");
// alert("tags="+tags.length);
for (loop=0;tags[loop];loop++)
{
if (file=tags[loop].src.match(/http:\/\/[^\&\?]+\.google\.[^\&\?]+\/([0-9]+)\/[^\&\?]+\/main\.js/)) {
//alert(file[1]);
document.getElementById("apiv").innerHTML = "API v2."+file[1];
}
}
//*************************************************************
You should be able to do the something similar for API v3.

Adding google maps markers by an address instead of coordinates?

In my Flex project, can I add markers by its address instead of this:
var myGeographicCoordinates:LatLng = new LatLng(myLatitude, myLongitude);
for example add marker by "Paris, France"
I don't think you can do so directly. Instead you need to geocode the address and then use a LatLng to store the result.
Check out google's geocoding api here:
http://code.google.com/apis/maps/documentation/geocoding/
You should read Google's developer manual on Geocoding. It explains how to convert an address to a geolocation. I recommend you try looking at the Dev manual/API/Google before posting here.

Resources