Google Map places API - search address by country and code postal - autocomplete

Please I want to use the autocomplete places API to get address based on country 'fr' and postal code like 87000
This is what I have done:
function initialize()
{
var quartier = document.getElementById('quartiers');
var request = {
types: ['geocode'],
componentRestrictions: {country: 'fr'}
};
var autocomplete = new google.maps.places.Autocomplete((quartier), request);
google.maps.event.addListener(autocomplete, 'place_changed', function(data)
{
//some code here
});
}
This one works great for country, but I don't know how to get it working with a specific postal code like 87000.
Any ideas?

Hi try change in this line
types: ['geocode'],
for this
types: ['regions'],
Regards

Related

Google Apps Script: Unable to send emails using createEvent()

I have the following code and attendees are not able to receive emails about the event. Though the event is reflecting in their calendar.
var options = {
description: description,
location: location,
guests: email_address,
sendInvites: true
}
var event = CalendarApp.getCalendarById(calendarId).createEvent(title,
start_datetime, end_datetime,
options);
I have added oauthScopes to appsscript.json as well.
"oauthScopes": [
"https://www.googleapis.com/auth/calendar",
"https://www.google.com/calendar/feeds"
]
It seems like an authorization issue but not sure how to solve this.
You don't need to manually add any scopes while running the script from the browser editor.
Your code worked perfectly for me :) I added a few variables to complete it but it worked just fine -
function myFunction() {
var calendarId = 'self#gmail.com'; // if using your own or default calendar ID
var description = 'test desc';
// ref link - https://developers.google.com/apps-script/reference/calendar/calendar-app#advanced-parameters_4
var email_address = 'contact1#gmail.com, contact2#gmail.com';
// comma separated guest list
var title = 'test title';
var start_datetime = new Date();
var end_datetime = new Date();
var options = {
description: description,
guests: email_address,
sendInvites: true
}
var event = CalendarApp
.getCalendarById(calendarId)
.createEvent(title, start_datetime, end_datetime, options);
}
My default manifest file looks like this -
{
"timeZone": "Asia/Kolkata",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER"
}
No additional scopes seem to have been added. However, when I view my File > Project properties > Scope, only a single scope seem to have been added by the script -
OAuth Scope required by script:
https://www.googleapis.com/auth/calendar
Hope this helps.
Edit note: Forgot to add -
Email notifications are being received as well

angular 2 patch value reactive forms returns undefined

after this..
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
let id = Number.parseInt(params['id']);
console.log('getting person with id: ', id);
this.peopleService
.get(id)
.subscribe(p => this.person = p);
});
}
why does
console.log(this.person);
return undefined?
code my code is based on this
It all works fine when I use it in the html, for example
{{person.id}}
and it works fine in my component.ts when I pass the data to a Material dialog using
data:this.activity
I've added
#input person:Person;
What do I need to do to be able to console.log(this.person) ?
The reason I'm asking is curiosity and also I need use patchValue on a reactive form and I get undefined if I add
this.personForm
// .patchValue({name:this.person.name});
I rewrote the subscribe line
.subscribe((response) =>{
this.person = response;
this.personForm
.patchValue({name:this.person.name});
});
and it works but probably not the nicest way to do it?

How to determine if address cannot be geocoded in JavaScript using MapQuest Map API

I need to geocode bunch of addresses and pin point them on the map using MapQuest. I am using
geocodeAndAddLocations
method to do that. The only problem I have is I can't figure out if geocoding for a certain address failed or not. Does anyone know how to determine that?
I have not tested this code, but according to MapQuest API, it would be something like this:
map.geocodeAndAddLocations([
{street:"555 17th St", postalCode:"80202"}
], function (response) {
if (response.results.length == 0) { // FAILED!!!
alert("can't geocode location");
} else { // SUCCESS
var location;
for (j=0; j<response.results[i].locations.length; j++) {
location = response.results[i].locations[j];
alert('lat: ' + location.latLng.lat + ', lng: ' + location.latLng.lng);
}
}
});
but again, having more of your code would give a better idea what exactly you are doing and not doing.
very simplest way...
use the following url in this jquery ajax to geocode. Even you are use mapquest
This ajax returns the json object.
$.getJSON("http://nominatim.openstreetmap.org/reverse?format=json&lat="+lat+"&lon="+lon+"", function(data) {
var loc=data.display_name;
});
append your lat and lng in the url.if unable to get the location details it throws the "unable to geocode " so you easily fix your problem.

Custom PhoneGap Plugin (iOS) Function Issue

I'm using this tutorial to create a custom PhoneGap plugin:
http://wiki.phonegap.com/w/page/36753496/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20iOS
I have had success using the author's example, but I have a few questions that I have not been able to find out the answers to.
When the JavaScript function is created, the code is:
var MyPlugin = {
nativeFunction: function(types, success, fail) {
return PhoneGap.exec(success, fail, "PluginClass", "print", types);
}
};
Is there a way to set this up without var MyPlugin = {...}; and nativeFunction? In other words, can we define a function of our plugin like myfunc = function()...
Secondly, assuming there is a way to do the above, could this code:
MyPlugin.nativeFunction(
["HelloWorld"] ,
function(result) {
alert("Success : \r\n"+result);
},
function(error) {
alert("Error : \r\n"+error);
}
);
(which is the test code to test the plugin) also be written in a more standardized way? I.e., just a call to Javascript function without the nativeFunction part?
I would very much appreciate any input, thank you!
the phonegap documentation for plugins sucks. Honestly I had a bunch of issues when trying to create my own. A few tips :
the reason for doing
var MyPlugin = {};
is because this allows us to us scope things specific to that js object.
example:
MyPlugin.myFunction();
My favorite method to create plugins, similar to your question, is to prototype them
var MyPlugin = {}; // our object
MyPlugin.prototype.myFunction = function(success,fail,types){
}
The key to making a plugin fire is this -
PhoneGap.exec(success,fail,"MyPlugin","myFunction",types);
But something that they leave out is, what if we want to have options to our plugin? What if we want to do more than pass a string, then the example doesn't work. The fix is easy but not talked about at all.
var MyPlugin = {};
MyPlugin.prototype.myFunction = function(success,fail,options){
var defaults = {
foo: '', // these are options
bar: '',
};
// this parses our "options"
for(var key in defaults) {
if(typeof options[key] !== "undefined") defaults[key] = options[key];
}
return PhoneGap.exec(success,fail,"MyPlugin","myFunction",[defaults]);
}
when we call this with out javascript -
var foo = MyPlugin.myFunction(success,fail,{
foo:'hello',
bar:'world'
});
You'll notice that most of the phonegap API uses this syntax, which I found strange that their documentation didn't really talk about how to do this.
I have a post about a plugin I create you can check it out for reference.
Blog - http://www.drewdahlman.com/meusLabs/?p=138
Git - https://github.com/DrewDahlman/ImageFilter

Facebook c# sdk get users email

I have a site which is using facebook for auth. I want to gather some basic info when a user signs up including their email address.
The code i have for the login is standard:
public ActionResult Login(string returnUrl)
{
var oAuthClient = new FacebookOAuthClient();
oAuthClient.AppId = AppSettings.GetConfigurationString("appId");
oAuthClient.RedirectUri = new Uri(AppSettings.GetConfigurationString("redirectUrl"));
var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", returnUrl } });
return Redirect(loginUri.AbsoluteUri);
}
How do i add the request to access permissions in that? Or do i do it another way?
You need to use the email permission (the full list is here: http://developers.facebook.com/docs/authentication/permissions/ )
The way to add permissions to the authorization is by appending a comma separated list to &scope= , e.g.:
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=email,read_stream
Update: As you marked, the parameters are passed to the GetLoginUrl() method, although in the codeplex forum they also used ExchangeCodeForAccessToken(), which you might want to take a look at also.
A couple of examples using the C# SDK:
http://blog.prabir.me/post/Facebook-CSharp-SDK-Writing-your-first-Facebook-Application.aspx
Facebook .NET SDK: How to authenticate with ASP.NET MVC 2
http://facebooksdk.codeplex.com/discussions/244568
A snoop at the sdk code and i came up wiht:
public ActionResult Login(string returnUrl)
{
var oAuthClient = new FacebookOAuthClient();
oAuthClient.AppId = AppSettings.GetConfigurationString("appId");
oAuthClient.RedirectUri = new Uri(AppSettings.GetConfigurationString("redirectUrl"));
var parameters = new Dictionary<string, object>();
parameters["state"] = returnUrl;
parameters["scope"] = "email";
var loginUri = oAuthClient.GetLoginUrl(parameters);
return Redirect(loginUri.AbsoluteUri);
}
not tested it yet and the missus is shouting at me for working late so will have to test tomoz :)