Code Monkey home page Code Monkey logo

googlemaps.locationservices's Introduction

GoogleMaps.LocationServices

A simple library for Google Maps geolocation and reverse geolocation.

The easiest way to get hold of it is to install the Nuget package.

From the package manager console: PM> Install-Package GoogleMaps.LocationServices

Example Lookup

using GoogleMaps.LocationServices;
.....

AddressData[] addresses = new AddressData[] 
{
    new AddressData // Belgium
    {
        Address = "Rue du Cornet 6",
        City = "VERVIERS",
        State = null,
        Country = "Belgium",
        Zip = "B-4800"
    },
    new AddressData
    {
        Address = "1600 Pennsylvania ave",
        City = "Washington",
        State = "DC"
    },
    new AddressData
    {
        Address = "407 N Maple Dr. #1",
        City = "Beverly Hills",
        State = "CA"
    }
};

// Constructor has 3 overload
// No parameters. It does not use API Key
var gls = new GoogleLocationService();

// Boolean parameter to force the requests to use https 
// var gls = new GoogleLocationService(useHttps: true);

// String paremeter that provides the google map api key
// var gls = new GoogleLocationService(apikey: "YOUR API KEY");
foreach (var address in addresses)
{
    try
    {
        var latlong = gls.GetLatLongFromAddress(address);
        var Latitude = latlong.Latitude;
        var Longitude = latlong.Longitude;
        System.Console.WriteLine("Address ({0}) is at {1},{2}", address, Latitude, Longitude);
    }
    catch(System.Net.WebException ex)
    {
        System.Console.WriteLine("Google Maps API Error {0}", ex.Message);
    }
                
}

googlemaps.locationservices's People

Contributors

a-a-k avatar adrotter avatar ash-grennan avatar bcuff avatar dkopack avatar iabusida avatar luis-palacios avatar mgravell avatar myles-mcdonnell avatar qwertydog avatar sethwebster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

googlemaps.locationservices's Issues

GetAddressFromLatLong Bad Request

Hi, I am trying to use Location services to resolve lat long coordinates into an address but when I am trying to use that method I get a 400 Bad Request, any idea Why?

GetAddressFromLatLang() returns empty AddressData object

Hello. I am using the Google Location Service API like this:

        var locationService = new GoogleLocationService(MyGoogleMapsApiKey);
        var addressData = locationService.GetAddressFromLatLang(latLong.Latitude, latLong.Longitude);

My latitude and longitude are being pulled in correctly. However when the second line runs, the addressData object is completely empty. It's weird because when I try hitting the URL it works fine:

https://maps.googleapis.com/maps/api/geocode/xml?latlng=43.0389025,-87.9064736&sensor=false&key=[myprivatekey]

While I could just use the URL in my code and emulate what you have in Git, that seems like a bad idea if you ever change your XML, then I'd have to update my code every time, etc. Thanks.

Would I need an API key?

I am currently writing an application to go commercial (hopefully). This framework is awesome and I am curious, I see where there has been an API key implementation, however I am wondering if it would be necessary?

For now, all I am doing is dropping Lat/Long and requesting Address or dropping address and requesting Lat/Long. Just would like to hear your thoughts? From my understanding and from what I have researched, an API key is not need?

Respectfully,

google api key website restrictions

Having trouble getting by the Google API Key restrictions.

I keep getting Request denied, it's likely you need to enable the necessary Google maps APIs

Any know what I should add to the restrictions list on the google admin console? I've tried:
*localhost*
*x.x.x.x* - my pc ip
*x.x.x.x* - my firewall ip
Even tried just *

If I interact with api via client javascript (not using this library) it works, same box. This library runs on the server though.
If I disable the restrictions this library works also. (not really an option after dev)

500 Error

I am getting a System.Net.WebException: 'The remote server returned an error: (500) Internal Server Error.' only when I search for Oklahoma City OK. Any ideas?

Here is my code:

var gls = new GoogleLocationService("API_KEY");
MapPoint mp = gls.GetLatLongFromAddress("Oklahoma City, OK, USA");

Thanks in advance,

Mike

Help Wanted: Build with Multi-Targeting

I no longer use Windows and can't build a version for net461 or other windows-specific targets.

I've build this for net standard 2.1 but need help with getting multi-targeting working.

Anyone available to help?

GetAddressFromLatLang return empty Address

Using the GetAddressFromLatLang it return empty address.

I suppose that is beacuse in Italian Culture, Point is the separator of decimal instead Comma.
But anyway i'm passing doubles to the function

MapPoint double issue

Hi

When I use this service to determine the latitude & longitude of an address, I get the MapPoint.
The issue I'm having is that these doubles are shown as 509543986.0 and not 50.9543986

kind regards

Dennis

Geolocation Precision

Hi,

Thank you for creating this library. It works great for me. Is there a way to increase geolocation precision? I only get 7 decimal points no matter how well I specify the address...

Request Not Authorized or Over QueryLimit

Hi
I am getting exception on "Request Not Authorized or Over QueryLimit" when running a test console app with my own google api key. Please i need help to figure out this issue.
image

image

Thanks

Unable to Install through NuGet

Could not install package 'GoogleMaps.LocationServices 1.2.0.2'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

NuGet Error!

Install-Package : Could not install package 'GoogleMaps.LocationServices 1.2.0.2'. You are trying to install this package into a project that targets 
'.NETFramework,Version=v4.6.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more 
information, contact the package author.
At line:1 char:1
+ Install-Package GoogleMaps.LocationServices
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Readme needs updated instructions

Hello,

Thanks for this library, I wanted to inform you that the instructions on the readme are not up to date. Eg: It doesn't show instructions about adding API Key. I added a pull request to update it

Please add postcode function

I really love your api it works perfect, but the only thing i really need is the postcode function.
I was searching for GetLatLongFromPostcode(33333) but unfortounetly it doesn´t exist. Is it possible to add this function, because on many websites it is possible to search for latlong via post code.
Greetings.

Optional Google Api Key

It would be useful if the location services class constructors took in an optional google api key. If present this would be used when making request.

GetLatLongFromAddress gives different coordinates via code

Hi
Thank you for this simple and fantastic package. I am wondering why GetLatLongFromAddress(address) gives different lat and longs for such a request on address "1412 , Norway" via the code. If i run the request URL via an browser then it returns correct coordinates. What i am doing wrong?

CODE VS BROWSER:

geocoordinates in code vs browser

Following is the response in xml that is returned running the code:
{
OK

country
political
<formatted_address>Norway</formatted_address>
<address_component>
<long_name>Norway</long_name>
<short_name>NO</short_name>
country
political
</address_component>


60.4720240
8.4689460

<location_type>APPROXIMATE</location_type>


57.8097000
4.0649000


71.3078000
31.3549999




57.8097000
4.0649000


71.3078000
31.3549999



<place_id>ChIJv-VNj0VoEkYRK9BkuJ07sKE</place_id>

}

exception from reversed address

Hi,
I am getting empty and exception from :
var gls = new GoogleLocationService("AIzaSyAzXXP9EpudRef0ac4ggTt4tmhFQ_8fsc4");
try
{

           AddressData reversedAddress = gls.GetAddressFromLatLang(40.7581764, -73.9830625);
           MessageBox.Show(reversedAddress.ToString());

            Directions d=  gls.GetDirections(new AddressData { Address = "777 8th ave", City = "New York", State = "NY", Zip = "10036" }, new AddressData { Address = "64 west 48 street", City = "New York", State = "NY", Zip = "10036" });
            MessageBox.Show(d.Distance.ToString());
        }
        catch (System.Net.WebException ex)
        {
            MessageBox.Show("Google Maps API Error {0}", ex.Message);
        }

Thanks

Anyone using this in a commercial application?

This might be the wrong place to ask this, but I am new to GitHub and would just like to see if anyone has used this framework in a commercial application. It is working flawlessly for me at the moment... writing in Vb.Net

Request denied, it's likely you need to enable the necessary Google maps APIs Error

Hi Sethwebster,

I recentky update the Nuget package for this repository and I'm getting this error every time I send a request to the Geocoding API. I go through the code and have seen that the error is thrown whenever Google API return "Request denied". I have enabled Geocoding API as part of my project, in fact, I have enabled all Google Map related APIs but I'm still getting this error.

Could this possibly be "Query Limit error"? Please help

Coordinates for addresses that are close by

When I look up for addresses which are close by (approx 1 km away from each other), I receive same coordinates for them. This results in overwriting of points on the map.

API Key not working?

I keep getting Request Not Authorized or Over QueryLimit when trying to get long lat from an address. I'm passing in my API key. DO I need to set something up in google maps to allow querys? Any help is greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.