Coder Social home page Coder Social logo

Comments (10)

valentasm1 avatar valentasm1 commented on August 14, 2024

Could you give use case?
Also example in JavaScript or elsewere?

from blazorgooglemaps.

ALMLAMBO avatar ALMLAMBO commented on August 14, 2024

This is the code in the browser.

GoogleMap map1;
	MapOptions mapOptions;

	protected override async Task OnInitializedAsync() {
		MapsCoordinatesBindingModel mapsCoordinates =
			await Task.Run(() => {
				return service
					.GetCoordinates("СПИДИ София - Младост 3 (жк), бл. 319, ж.к. Младост 3, София")
					.Result;
			});

		mapOptions = new MapOptions() {
			Zoom = 13,

			Center = new LatLngLiteral() {
				Lat = mapsCoordinates.Lat,
				Lng = mapsCoordinates.Lng
			},
			MapTypeId = MapTypeId.Sattellite
		};
	}
}

I am using Geocoding to get coordinates of a place.

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

Thank you. I will take a look today.

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

Could you provide full example? You could remove or change sensitive data.
I dont understand what is service. What is MapsCoordinatesBindingModel. Also i dont understand what you are trying to archive.
Maybe you could try to download GitHub solution and tryout MapAutocomplete page on server side. You could debut it and it will help you find how it works. I think you need Autocomplete.GetPlace method call.

from blazorgooglemaps.

willapp avatar willapp commented on August 14, 2024

To make Autocomplete work, you need something like the following:

<input type="text" @ref="this.searchBox" id="searchBox" />
<GoogleMap @ref="@map1" Id="map1" Options="@mapOptions" Height="500" OnAfterInit="@(async () => await OnAfterMapInitAsync())"></GoogleMap>

@code {
  private GoogleMap map1;
  private MapOptions mapOptions;
  private ElementReference searchBox;
  private Autocomplete autocomplete;

  protected override void OnInitialized()
  {
    this.mapOptions = new MapOptions
    {
        Zoom = 13,
        Center = new LatLngLiteral
        {
            Lat = 40.621875,
            Lng = -74.125255
        },
        MapTypeId = MapTypeId.Roadmap
    };
  }

  private async Task OnAfterMapInitAsync()
  {     
    this.autocomplete = await Autocomplete.CreateAsync(this.map1.JsRuntime, this.searchBox, new AutocompleteOptions
        {
            StrictBounds = false
        });

    await this.autocomplete.AddListener("place_changed", async () => await this.MapSearchPlaceChanged());
  }

  private async Task MapSearchPlaceChanged()
  {
    var place = await this.autocomplete.GetPlace();

    if (place?.Geometry?.Location != null)
    {
      // do something with the place.Geometry.Location
    }
  }
}

from blazorgooglemaps.

ALMLAMBO avatar ALMLAMBO commented on August 14, 2024

I want to ask how I can use MapAutocomplete from the library?

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

Could you confirm it is it what you want to do.
Pass address name "СПИДИ София - Младост 3 (жк), бл. 319, ж.к. Младост 3, София" or similar
Get first coordinates (lat, lng) from result
Return that coordinates

Am i right?

from blazorgooglemaps.

ALMLAMBO avatar ALMLAMBO commented on August 14, 2024

Yes.

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

It looks like you need geocoding which is not implemented in here. It is not directly related to google maps. I dont want to spend time implementing it here since there are already libraries who does that.
After you get lat lng then you could set it to map
await this.map1.InteropObject.SetCenter(new LatLngLiteral(){ Lat = 12.12 , Lng = 25.25});

Here is nuget for that
https://github.com/chadly/Geocoding.net

Examples on stackoverflow
https://stackoverflow.com/questions/16274508/how-to-call-google-geocoding-service-from-c-sharp-code

from blazorgooglemaps.

valentasm1 avatar valentasm1 commented on August 14, 2024

Closing due innactivity.

from blazorgooglemaps.

Related Issues (20)

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.