How to find the name of current place in windows phone 8? - windows-phone-8

I am able to get the latitude and longitude using Geoposition class.How can I find the name of the current location in windows phone 8?

You have a built-in API for reverse geocoding in Windows Phone 8. You can do it as follows, for example, to ghet the name of the city:
string address;
ReverseGeocodeQuery query = new ReverseGeocodeQuery();
query.GeoCoordinate = yourGeoCoordinateObject;
query.QueryCompleted += (s, e) =>
{
if (e.Error != null)
return;
address = e.Result[0].Information.Address.City;
};
query.QueryAsync();

This is known as Reverse Geocoding. Google offer this as part of their Geocoding API. The specific reference is here
You can make a call to their API with a simple HTTP request:
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true
And they'll return a list of human-readable names in JSON format.

Related

Xamarin App Sends Json Data When Phone Virtual But Doesn't Send Physical

I don't know where to look or what to check but ask my question in title. Xamarin forms app works when sending json data over virtual phone instance but doesn't send data over physical no matter which platform i use , it is the same with iOS and Android.
static async Task phoneInfo()
{
string url = "http://blabla.com/api/blabla";
string sContentType = "application/json";
JObject jsonObject = new JObject();
jsonObject.Add("DeviceModel", DeviceInfo.Model);
jsonObject.Add("DeviceManufacturer", DeviceInfo.Manufacturer);
jsonObject.Add("DeviceName", DeviceInfo.Name);
jsonObject.Add("DeviceVersion", DeviceInfo.VersionString);
jsonObject.Add("DevicePlatform", DeviceInfo.Platform);
jsonObject.Add("DeviceIdiom", DeviceInfo.Idiom);
jsonObject.Add("DeviceType", DeviceInfo.DeviceType.ToString());
jsonObject.Add("AreaOne", DateTime.UtcNow.ToString());
jsonObject.Add("Deleted", false);
HttpClient oHttpClient = new HttpClient();
var oTaskPostAsync = await oHttpClient.PostAsync(url, new StringContent(jsonObject.ToString(), Encoding.UTF8, sContentType));
}
usage is simple like code. just put await phoneInfo(); where i want to take info.
i have accesswifistate and internet permission over Android and NSAppTransportSecurity for non https connection with iOS.
Any ideas where am i doing wrong?

What is the efficient way to get the fields from this JSON object?

I've the following code that returns json object. And I need to filter sender email, subject, and creationDate. The code does the job but I felt like there is an efficient way to do it. I appreciate your suggestion.
ResponseEntity<String> response =
restTemplate.exchange(app.getResourceUrl() + personnelEmail+
MESSAGE+"/?$select=Sender,Subject,CreatedDateTime", HttpMethod.GET, request, String.class);
String str=response.getBody();
JSONObject jsonObject= new JSONObject(str);
JSONArray arrayList= (JSONArray)jsonObject.get("value");
List l=arrayList.toList();
for(int i=0;i<l.size();i++){
HashMap<String,HashMap> hashMap=(HashMap<String,HashMap>)l.get(i);
HashMap<String,HashMap> sender= hashMap.get("sender");
HashMap<String,String> senderEmail= sender.get("emailAddress");
String email= senderEmail.get("address");
}
Here is the json object I receive from MS Office API.
{"#odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('user34.onmicrosoft.com')/messages(sender,subject,createdDateTime)","value":[{"#odata.etag":"W/\”sljkasfdiou7978klosadf\"","id”:"lkjasdfu97978KLJASDFS_WGHJJ76J897DKdcuvtymBTItq836K34PUAAAvoK3SAAA=","createdDateTime":"2016-08-27T04:07:08Z","subject":"View
your Office 365 Enterprise E3 billing
statement","sender":{"emailAddress":{"name":"Microsoft Online Services
Team","address”:"T45763#email.microsoftonline.com"}}},{"#odata.etag":"W/\”JUU70303\"","id”:”UEYO93988FK;O38GV3J884=","createdDateTime":"2016-08-26T15:28:47Z","subject":"Order
confirmation: Thank you for your
purchase","sender":{"emailAddress":{"name":"Microsoft Online Services
Team","address":"obue733#email.microsoftonline.com"}}},{"#odata.etag":"W/\”LJKOIU987983\"","id”:”ladjksflk83l.x8783LKFW3=","createdDateTime":"2016-06-24T03:03:26Z","subject":"Attention:
Your Microsoft Azure Active Directory Premium trial subscription will
be disabled soon","sender":{"emailAddress":{"name":"Microsoft Online
Services Team","address":"635cdeee#email.microsoftonline.com"}}}]}
By default Office 365 REST API response payload also includes common annotations such as:
odata.context: the context URL of the payload
odata.etag: the ETag of the entity, as appropriate
The below picture demonstrates it
As you've already might guessed it could be controlled via odata.metadata parameter:
The odata.metadata parameter can be applied to the Accept header of
an OData request to influence how much control information will be
included in the response.
Example (C# version)
The example demonstrates how to set odata.metadata=none format parameter via Accept header to indicate that the service SHOULD omit control information
using (var client = new HttpClient(handler))
{
var url = "https://outlook.office365.com/api/v1.0/me/messages?$select=Sender,Subject,DateTimeCreated";
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse(GetMediaType("none",false,false)));
var result = await client.GetStringAsync(url);
var data = JObject.Parse(result);
foreach (var item in data["value"])
{
//process item;
}
}
where
private static string GetMediaType(string metadata,bool streaming,bool IEEE754Compatible)
{
return String.Format("application/json; OData.metadata={0}; OData.streaming={1}; IEEE754Compatible={2}",metadata,streaming, IEEE754Compatible);
}

Geocode rest api - filter for only latitude and longitude

I have a restful URL to look up an address using google's geocoding service. It works but provides me more information that what i need. Is there a way to only return the latitude and longditude part of the json result.
http://maps.google.com/maps/api/geocode/json?address=300+Collins+St,+Docklands,+VIC&sensor=false&components=country:AU
According to Geocoding Responses:
Note that the JSON response contains two root elements:
"status" contains metadata on the request. See Status Codes below.
"results" contains an array of geocoded address information and geometry information.
Generally, only one entry in the "results" array is returned for
address lookups,though the geocoder may return several results when
address queries are ambiguous.
The following example demonstrates how to extract location values from the returned JSON results:
var requestUrl = "https://maps.google.com/maps/api/geocode/json?address=300+Collins+St,+Docklands,+VIC&sensor=false&components=country:AU";
$.getJSON(requestUrl).done(function(data) {
//extract locations
var locations = data.results.map(function(item){
return item.geometry.location;
});
//print locations
var output = JSON.stringify(locations, null, 2);
$("#output").text(output);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre style="background-color: #c0c0c0" id="output"></pre>
As far as I remember, there's no other possibility. That's the standard return value. Try to use a filter in your program. You could split CSV file and cut off the needed part.

google places api INVALID_REQUEST

https://maps.googleapis.com/maps/api/place/details/json?reference=CmRYAAAAciqGsTRX1mXRvuXSH2ErwW-jCINE1aLiwP64MCWDN5vkXvXoQGPKldMfmdGyqWSpm7BEYCgDm-iv7Kc2PF7QA7brMAwBbAcqMr5i1f4PwTpaovIZjysCEZTry8Ez30wpEhCNCXpynextCld2EBsDkRKsGhSLayuRyFsex6JA6NPh9dyupoTH3g&key=AddYourOwnKeyHere
In this request url i needs to know what is the "reference" contains. Actually that is the Search text needs to be passed to api. but i have used the encoding the string before sending to api call like this
private String getPlacesUrl(String query) {
try {
query = "input=" + URLEncoder.encode(query, "utf-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
return query;
}
but still it is sending the query as normal encoded string like "London".
How to achieve the reference like encoding what given in Google api request. can any one help me...
Use this following link.There are some examples.maybe it will help you.
http://www.w3docs.com/learn-javascript/places-autocomplete.html
while searching places in Autocomplete search we should send the request to get the Places Details url. your Structure should be similar to this:
private String getPlaceDetailsUrl(String ref){
// reference of place
String reference = "reference="+ref;
// Sensor enabled
String sensor = "sensor=false";
// Building the parameters to the web service
String parameters = reference+"&"+sensor+"&"+mKey;
// Output format
String output = "json";
// Building the url to the web service
String url = "https://maps.googleapis.com/maps/api/place/details/"+output+"?"+parameters;
return url;
}
For More details refer this site as base. It's pretty good.
google Places autocomplete api

Using Google Maps API - sensor true or false REQUEST_DENIED

I'm trying to use Maps API from my mobile application in a similar manner as I can do using my Firefox browser:
http://maps.googleapis.com/maps/api/geocode/json?address=First Avenue New York Manhattan&sensor=true
Unfortunately, I always receive this error result: The 'sensor' parameter specified in the request must be set to either 'true' or 'false'
I tried TRUE, True, true... no way.
I also tried to use my API Key associated to my google account following this guide: https://developers.google.com/maps/documentation/javascript/tutorial?hl=it#api_key
In fact, I did:
http://maps.googleapis.com/maps/api/geocode/json?key={my_key}&address=First Avenue New York Manhattan&sensor=true
So, finally, I suppose my problems are related to the POST Request I prepared.
This is the code I use for my Request:
request = new CIwHTTP; // The http pointer
const char* c1 = text.getCString(); // This is the string "address=First Avenue New York Manhattan&sensor=true"
int length = strlen(c1);
request->SetRequestHeader("Content-Type", "text/javascript; charset=utf-8");
request->Post("http://maps.googleapis.com/maps/api/geocode/json", c1, length, callback, NULL);
In the callback I got my result string, hopefully the JSON string coming from Google telling me the address list. I'm not so sure about the Header, but I changed few of them without results.
I use Marmalade, so my code is fully C++.
Could you help me?
It seems Google doesn't like spaces in the address string and the call should be a GET call.
This is my working code:
CCString gURL = "http://maps.googleapis.com/maps/api/geocode/json?"; // URL base
CCString *string_final = CCString::createWithFormat( (
std::string(gURL.getCString()) +
std::string(text.getCString()) /* i.e. "address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false" */
).c_str() );
request->Get(string_final->getCString(),callback, NULL);