Я хочу получить лат и лонг на основе адреса.Я уже установил его так, чтобы он захватывал местоположение пользователей, которое вызывает его как Манчестер.
Я хочу написать оператор if ..................;
if there is an address
{
// set lat/long from address
}
вот полное кодирование;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GeoCoding.Google;
using GeoCoding;
using System.Web.Configuration;
namespace MVCFacebookTestApp.Models
{
public class Home
{
//public string UserID { get; set; }
public string FBID { get; set; }
public string AccessToken { get; set; }
public string FName { get; set; }
public string LName { get; set; }
public string Gender { get; set; }
public DateTime? DOB { get; set; }
public string Email { get; set; }
public DateTime DateLiked { get; set; }
public string ImageURL { get; set; }
//public string TestString { get; set; }
//public string TestString2 { get; set; }
public bool IsLiked { get; set; }
//public string ImgUrl { get; set; }
private Home() {
//Console.WriteLine(GoogleAPIKey);
}
public static Home NotLiked()
{
Home h = new Home();
h.IsLiked = false;
return h;
}
public static Home Liked()
{
Home h = new Home();
h.IsLiked = true;
return h;
}
public void AddUser(string facebookID, string accessToken, string fName, string lName, DateTime dob, string email, DateTime dateLiked, string gender, string imageURL, string locationID, string locationValue)
{
Entities context = new Entities();
//DBNameDataContext myDB = new DBNameDataContext();
IEnumerable<User> users = context.Users.Where(u => u.FacebookID == facebookID);
if (users.Count() == 0)
{
//UserID = userID;
FBID = facebookID;
AccessToken = accessToken;
FName = fName;
LName = lName;
DOB = dob;
Email = email;
DateLiked = dateLiked;
Gender = gender;
ImageURL = imageURL;
User newUser = new User();
//newUser.UserID = 1;
newUser.FacebookID = facebookID;
newUser.AccessToken = accessToken;
newUser.FName = fName;
newUser.LName = lName;
newUser.Gender = gender;
newUser.DOB = DOB;
newUser.Email = email;
newUser.DateLiked = dateLiked;
newUser.ImageURL = imageURL;
context.Users.AddObject(newUser);
context.SaveChanges();
}
else if (users.Count() == 1)
{
User user0 = users.First();
if (user0.Gender != gender)
{
user0.Gender = gender;
}
if (user0.FName != fName)
{
user0.FName = fName;
}
if (user0.LName != lName)
{
user0.LName = lName;
}
if (user0.DOB != dob)
{
user0.DOB = dob;
}
if (user0.Email != email)
{
user0.Email = email;
}
if (user0.DateLiked != dateLiked)
{
user0.DateLiked = dateLiked;
}
if (user0.ImageURL != imageURL)
{
user0.ImageURL = imageURL;
}
context.SaveChanges();
FBID = user0.FacebookID;
AccessToken = user0.AccessToken;
FName = user0.FName;
LName = user0.LName;
DOB = user0.DOB;
Email = user0.Email;
DateLiked = user0.DateLiked;
Gender = user0.Gender;
ImageURL = user0.ImageURL;
}
else
{
throw new ApplicationException();
}
//LOCATION...
//LocationID = locationID;
//FBID = facebookID;
//Latitude = latitude;
//Langitude = langitude;
//Description = description;
//IEnumerable<User> users = context.Users.Where(u => u.FacebookID == facebookID);
IEnumerable<Location> locations = context.Locations.Where(l => l.FacebookID == facebookID);
{
Location newLocation = new Location();
newLocation.FacebookID = locationID;
newLocation.Latitude = "";
newLocation.Langitude = "";
newLocation.Description = locationValue;
IGeoCoder geoCoder = new GoogleGeoCoder(GoogleAPIKey);
Address[] addresses = geoCoder.GeoCode(locationValue);
context.Locations.AddObject(newLocation);
context.SaveChanges();
}
if (Address= true)
{
langtitude = ;;
}
}
public string GoogleAPIKey
{
get
{
return WebConfigurationManager.AppSettings["GoogleAPIKey"];
}
}
}
}